• This repository has been archived on 13/Sep/2019
  • Stars
    star
    350
  • Rank 116,777 (Top 3 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created almost 7 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

MOVED to the bazel nodejs monorepo πŸ‘‰

CircleCI

Moved to rules_nodejs monorepo: https://github.com/bazelbuild/rules_nodejs/tree/master/examples/angular

Readme content is preserved below to avoid breaking links

This is experimental, as part of Angular Labs! There may be breaking changes.

This is part of the ABC project. The overall goal is to make it possible to develop Angular applications the same way we do at Google.

Learn more about Bazel and Angular at https://bazel.angular.io

This example is deployed at https://bazel.angular.io/example

Guide to the example

This example is a monorepo, meant to show many different features and integrations that we expect are generally useful for enterprise use cases.

  • Angular CLI: you can use the ng command to run build, serve, test, and e2e
  • Angular Libraries: to maximize build incrementality, each Angular module is compiled as a separate step. This lets us re-use Angular libraries without having to publish them as npm packages. See src/todos for a typical NgModule compiled as a library for use in the application, using the ng_module rule in the BUILD.bazel file.
  • TypeScript Libraries: see src/lib for a trivial example of a pure-TS library that's consumed in the application, using the ts_library rule in the BUILD.bazel file.
  • Sass: we use Sass for all styling. Angular components import Sass files, and these are built by Bazel as independent processes calling the modern Sass compiler (written in Dart).
  • Material design: see src/material where we collect the material modules we use.
  • Redux-style state management: see src/reducers where we use the NgRx Store.
  • Lazy loading: in production mode, the application is served in chunks. Run ng serve --prod
  • Differential loading: in production mode, we load a pair of <script> tags. Modern browsers will load code in the ES2015 syntax, which is smaller and requires fewer polyfills. Older browsers will load ES5 syntax.
  • Docker: see below where we package up the production app for deployment on Kubernetes.

Installation

You only need to install one build tool, and which one you choose typically depends on what kind of development you do most often.

If you're a frontend developer, you should install NodeJS and yarn. The package.json file has an engines section which indicates the range of NodeJS and yarn versions that you could use. You simply run yarn commands shown below, and don't need to install Bazel or any other dependencies.

If you're a full-stack developer, you might be using Bazel for your backend already. In this case, you should install Bazel following instructions at http://bazel.build. Also install ibazel, which is a watch mode for Bazel not included in the standard distribution. See https://github.com/bazelbuild/bazel-watcher#installation. The WORKSPACE file has a check_bazel_version call which will print an error if your Bazel version is not in the supported range. You simply run bazel commands shown below, and don't need to install NodeJS, yarn, or any other dependencies.

Development

First we'll run the development server:

$ ng serve
# or
$ ibazel run //src:devserver

This runs in "watch mode", which means it will watch any files that are inputs to the devserver, and when they change it will ask Bazel to re-build them. When the re-build is finished, it will trigger a LiveReload in the browser.

This command prints a URL on the terminal. Open that page to see the demo app running. Now you can edit one of the source files (src/lib/file.ts is an easy one to understand and see the effect). As soon as you save a change, the app should refresh in the browser with the new content. Our intent is that this time is less than two seconds, even for a large application.

Control-C twice to kill the devserver.

Testing

We can also run all the unit tests:

$ ng test
# or
$ bazel test //src/...

Or run the end-to-end tests:

$ ng e2e
# or
$ bazel test //e2e/...

In this example, there is a unit test for the hello-world component which uses the ts_web_test_suite rule. There are also protractor e2e tests for both the prodserver and devserver which use the protractor_web_test_suite rule.

Note that Bazel will only re-run the tests whose inputs changed since the last run.

Production

We can run the application in production mode, where the code has been bundled and optimized. This can be slower than the development mode, because any change requires re-optimizing the app. This example uses Rollup and Uglify, but other bundlers can be integrated with Bazel.

$ ng serve --prod
# or
$ bazel run //src:prodserver

Code splitting

The production bundle is code split and routes such as / and /todos are lazy loaded. Code splitting is handled by the rollup_bundle rule which now supports the new code splitting feature in rollup.

Note: code splitting is not supported in development mode yet so the //src:devserver target does not serve a code split bundle. The dynamic import() statements will resolve to modules that are served in the initial JS payload.

Npm dependencies

Having a local node_modules folder setup by yarn or npm is not necessary when building this example with Bazel. This example makes use of Bazel managed npm dependencies (https://github.com/bazelbuild/rules_nodejs#using-bazel-managed-dependencies) which means Bazel will setup the npm dependencies in your package.json for you outside of your local workspace for use in the build.

However, you may still want to run yarn or npm to manually setup a local node_modules folder for editor and tooling support.

Deployment

Firebase

We use the standard firebase deploy command.

Run yarn deploy to release changes to bazel.angular.io.

Kubernetes Engine

We use Bazel's docker support to package up our production server for deployment. Each time the app changes, we'll get a slim new docker layer with just the modified files, keeping the round-trip for deployment incremental and fast. This example is configured to run on Google Kubernetes Engine, so we can have an elastic pool of backend machines behind a load balancer. This setup is more expensive to operate than something like Firebase Functions where the backend code is spun up on-demand, but is also more adaptable to scenarios like backend servers that need to run other binaries on the machine.

The application is currently live at http://35.197.115.230/

To run it under docker:

$ bazel run src:nodejs_image -- --norun
$ docker run --rm -p 8080:8080 bazel/src:nodejs_image

Deploy to production:

  1. Install gcloud and kubectl
  2. Authenticate to the Google Container Registry gcloud auth configure-docker
  3. Authenticate to Kubernetes Engine gcloud container clusters get-credentials angular-bazel-example --zone=us-west1-a
  4. For the first deployment: bazel run :deploy.create
  5. To update: bazel run :deploy.replace

Tips:

# Run the binary without docker
$ bazel run src:nodejs_image.binary
 # What's in the image?
$ bazel build src:nodejs_image && file-roller dist/bin/src/nodejs_image-layer.tar
 # Tear down all running docker containers
$ docker rm -f $(docker ps -aq)
 # Hop into the running image on kubernetes
$ kubectl exec angular-bazel-example-prod-3285254973-ncv3g  -it -- /bin/bash

More Repositories

1

angular

The modern web developer’s platform
TypeScript
91,840
star
2

angular.js

AngularJS - HTML enhanced for web apps!
JavaScript
59,091
star
3

angular-cli

CLI tool for Angular
TypeScript
26,587
star
4

components

Component infrastructure and Material Design components for Angular
TypeScript
24,075
star
5

material

Material design for AngularJS
JavaScript
16,637
star
6

angular-seed

Seed project for angular apps.
JavaScript
13,050
star
7

protractor

E2E test framework for Angular apps
JavaScript
8,780
star
8

angularfire

Angular + Firebase = ❀️
TypeScript
7,595
star
9

flex-layout

Provides HTML UI layout for Angular applications; using Flexbox and a Responsive API
TypeScript
5,911
star
10

universal

Server-side rendering and Prerendering for Angular
TypeScript
4,029
star
11

zone.js

Implements Zones for JavaScript
TypeScript
3,243
star
12

quickstart

Angular QuickStart - source from the documentation
JavaScript
3,128
star
13

angular-phonecat

Tutorial on building an angular application.
JavaScript
3,128
star
14

batarang

AngularJS WebInspector Extension for Chrome
JavaScript
2,444
star
15

material-start

Starter Repository for AngularJS Material
JavaScript
2,214
star
16

universal-starter

Angular Universal starter kit by @AngularClass
TypeScript
2,028
star
17

mobile-toolkit

Tools for building progressive web apps with Angular
JavaScript
1,344
star
18

in-memory-web-api

The code for this project has moved to the angular/angular repo. This repo is now archived.
TypeScript
1,172
star
19

angular.io

Website for the Angular project (see github.com/angular/angular for the project repo)
HTML
1,032
star
20

angular2-seed

TypeScript
1,011
star
21

tsickle

Tsickle β€” TypeScript to Closure Translator
TypeScript
893
star
22

material.angular.io

Docs site for Angular Components
TypeScript
859
star
23

di.js

Dependency Injection Framework for the future generations...
JavaScript
822
star
24

react-native-renderer

Use Angular and React Native to build applications for Android and iOS
TypeScript
789
star
25

dgeni

Flexible JavaScript documentation generator used by AngularJS, Protractor and other JS projects
TypeScript
770
star
26

angular-cn

Chinese localization of angular.io
Pug
761
star
27

vscode-ng-language-service

Angular extension for Visual Studio Code
TypeScript
757
star
28

router

The Angular 1 Component Router
JavaScript
667
star
29

angular-electron

Angular2 + Electron
TypeScript
610
star
30

devkit

549
star
31

bower-material

This repository is used for publishing the AngularJS Material v1.x library
JavaScript
506
star
32

watchtower.js

ES6 Port of Angular.dart change detection code.
JavaScript
410
star
33

preboot

Coordinate transfer of state from server to client view for isomorphic/universal JavaScript web applications
TypeScript
384
star
34

angular-hint

run-time hinting for AngularJS applications
JavaScript
368
star
35

builtwith.angularjs.org

builtwith.angularjs.org
HTML
271
star
36

protractor-accessibility-plugin

Runs a set of accessibility audits
JavaScript
263
star
37

angularjs.org

code for angularjs.org site
JavaScript
260
star
38

angular-update-guide

An interactive guide to updating the version of Angular in your apps
TypeScript
245
star
39

webdriver-manager

A binary manager for E2E testing
TypeScript
227
star
40

bower-angular

Bower package for AngularJS
CSS
224
star
41

angular-ja

repository for Japanese localization of angular.io
HTML
208
star
42

ngSocket

WebSocket support for angular
JavaScript
204
star
43

peepcode-tunes

Peepcode's Backbone.js Music Player Reimplemented in AngularJS
JavaScript
204
star
44

clutz

Closure to TypeScript `.d.ts` generator
Java
163
star
45

benchpress

JavaScript
160
star
46

code.angularjs.org

code.angularjs.org
153
star
47

ngcc-validation

Angular Ivy library compatibility validation project
TypeScript
146
star
48

dgeni-packages

A collection of dgeni packages for generating documentation from source code.
JavaScript
143
star
49

bower-angular-route

angular-route bower repo
JavaScript
143
star
50

atscript-playground

A repo to play with AtScript.
JavaScript
141
star
51

bower-angular-animate

Bower package for the AngularJS animation module
JavaScript
137
star
52

protractor-cookbook

Examples for using Protractor in various common scenarios.
TypeScript
130
star
53

diary.js

Flexible logging and profiling library for JavaScript
JavaScript
127
star
54

bower-angular-i18n

internationalization module for AngularJS
JavaScript
125
star
55

ts-minify

A tool to aid minification of Typescript code, using Typescript's type information.
TypeScript
119
star
56

closure-demo

TypeScript
114
star
57

ngMigration-Forum

109
star
58

material-adaptive

Adaptive template development with Angular Material
JavaScript
101
star
59

watScript

The next generation JavaScript language that will kill ALL the frameworks!
101
star
60

bower-angular-sanitize

angular-sanitize bower repo
JavaScript
99
star
61

code-of-conduct

A code of conduct for all Angular projects
99
star
62

clang-format

Node repackaging of the clang-format native binary
Python
97
star
63

tactical

Data access library for Angular
TypeScript
93
star
64

bower-angular-resource

angular-resource bower repo
JavaScript
92
star
65

dashboard.angularjs.org

AngularJS Dashboard
JavaScript
89
star
66

angular-jquery-ui

jQueryUI widgets wrapped as angular widgets
JavaScript
88
star
67

bower-angular-mocks

angular-mocks.js bower repo
JavaScript
87
star
68

bower-angular-cookies

angular-cookies bower repo
JavaScript
85
star
69

issue-zero

TypeScript
82
star
70

bower-angular-touch

JavaScript
79
star
71

templating

Templating engine for Angular 2.0
JavaScript
76
star
72

a

Library for annotating ES5
JavaScript
67
star
73

material-icons

Common resources for material design in AngularJS
66
star
74

vladivostok

TypeScript
65
star
75

bower-angular-messages

JavaScript
63
star
76

angular-component-spec

Specification for reusable AngularJS components
61
star
77

ci.angularjs.org

ci.angularjs.org CI server scripts
Shell
60
star
78

projects

github reference application for Angular 2.0
JavaScript
58
star
79

dev-infra

Angular Development Infrastructure
JavaScript
57
star
80

code.material.angularjs.org

Documentation site for AngularJS Material
HTML
50
star
81

material-tools

Tools for AngularJS Material
TypeScript
47
star
82

jasminewd

Adapter for Jasmine-to-WebDriverJS
JavaScript
46
star
83

material-update-tool

Standalone update tool for updating Angular CDK and Material
TypeScript
46
star
84

material-builds

Build snapshots for @angular/material
JavaScript
45
star
85

material2-docs-content

Docs content for @angular/material
HTML
37
star
86

benchpress-tree

A reference implementation of a benchpress deep-tree benchmark as seen in Angular
JavaScript
37
star
87

cdk-builds

Angular CDK builds
JavaScript
37
star
88

router-builds

@angular/router build artifacts
JavaScript
36
star
89

angular-ko

HTML
36
star
90

prophecy

Deferred/Promise for AngularJS 2.0
JavaScript
36
star
91

answers-app

TypeScript
36
star
92

assert

A runtime type assertion library.
JavaScript
35
star
93

ngo

TypeScript
34
star
94

protractor-console-plugin

Checks the browser log after each test for warnings and errors
JavaScript
34
star
95

codelabs

31
star
96

introduction-to-angular

TypeScript
31
star
97

microsites

Master repository for sites on the angular.io subdomains (universal.angular.io, material.angular.io, etc)
HTML
29
star
98

core-builds

@angular/core build artifacts
JavaScript
29
star
99

ngtools-webpack-builds

Build artifacts for @ngtools/webpack
JavaScript
28
star
100

service-worker-builds

Build artifacts for @angular/service-worker
JavaScript
27
star