|
1 | | -## Angular CLI |
| 1 | +## Angular CLI: Bazel Branch |
2 | 2 | ### CLI for Angular applications based on the [ember-cli](http://www.ember-cli.com/) project. |
3 | 3 |
|
4 | 4 | <!-- Badges section here. --> |
|
19 | 19 | [](https://github.com/angular/angular-cli) |
20 | 20 |
|
21 | 21 |
|
22 | | -## Note |
| 22 | +## EXPERIMENTAL |
23 | 23 |
|
24 | | -The CLI is now in 1.0. |
25 | | -If you are updating from a beta or RC version, check out our [1.0 Update Guide](https://github.com/angular/angular-cli/wiki/stories-1.0-update). |
| 24 | +**This is an EXPERIMENTAL early version of the bazel support. ** |
26 | 25 |
|
27 | | -If you wish to collaborate, check out [our issue list](https://github.com/angular/angular-cli/issues). |
| 26 | +Read more about bazel here: [Building Angular apps at scale](https://medium.com/@Jakeherringbone/building-angular-apps-at-scale-813ef42add04). |
28 | 27 |
|
29 | 28 | Before submitting new issues, have a look at [issues marked with the `type: faq` label](https://github.com/angular/angular-cli/issues?utf8=%E2%9C%93&q=is%3Aissue%20label%3A%22type%3A%20faq%22%20). |
30 | 29 |
|
| 30 | + |
| 31 | + |
| 32 | + |
31 | 33 | ## Prerequisites |
32 | 34 |
|
33 | 35 | Both the CLI and generated project have dependencies that require Node 6.9.0 or higher, together |
34 | 36 | with NPM 3 or higher. |
35 | 37 |
|
| 38 | +### Bazel and iBazel |
| 39 | + |
| 40 | +* Make sure you have [Bazel](https://bazel.build/) installed. |
| 41 | +* Make sure you have [Bazel Watcher](https://github.com/bazelbuild/bazel-watcher) compiled and installed. |
| 42 | + |
36 | 43 | ## Table of Contents |
37 | 44 |
|
38 | 45 | * [Installation](#installation) |
39 | 46 | * [Usage](#usage) |
40 | | -* [Generating a New Project](#generating-and-serving-an-angular-project-via-a-development-server) |
41 | | -* [Generating Components, Directives, Pipes and Services](#generating-components-directives-pipes-and-services) |
42 | | -* [Updating Angular CLI](#updating-angular-cli) |
43 | | -* [Development Hints for working on Angular CLI](#development-hints-for-working-on-angular-cli) |
44 | | -* [Documentation](#documentation) |
45 | 47 | * [License](#license) |
46 | 48 |
|
47 | 49 | ## Installation |
48 | 50 |
|
49 | 51 | **BEFORE YOU INSTALL:** please read the [prerequisites](#prerequisites) |
50 | 52 | ```bash |
51 | 53 | npm install -g @angular/cli |
| 54 | +npm install -g @nrwl/bazel |
52 | 55 | ``` |
53 | 56 |
|
54 | | -## Usage |
| 57 | +### @Nrwl/Bazel? |
| 58 | + |
| 59 | +THe bazel support is a collaboration of the Angular team at Google and the [Nrwl](http://nrwl.io) team. At the moment, some code lives under `@nrwl`, but it will move under `@angular` once it stabilizes. |
| 60 | + |
55 | 61 |
|
56 | | -```bash |
57 | | -ng help |
58 | | -``` |
59 | 62 |
|
60 | | -### Generating and serving an Angular project via a development server |
| 63 | +## [Usage](#usage) |
| 64 | + |
| 65 | +### Generate an Angular Workspace |
61 | 66 |
|
62 | 67 | ```bash |
63 | | -ng new PROJECT-NAME |
| 68 | +ng new PROJECT-NAME --collection=@nrwl/bazel |
64 | 69 | cd PROJECT-NAME |
65 | | -ng serve |
66 | 70 | ``` |
67 | | -Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. |
68 | 71 |
|
69 | | -You can configure the default HTTP host and port used by the development server with two command-line options : |
| 72 | +This is an empty Angular workspace. |
| 73 | + |
| 74 | + |
| 75 | + |
| 76 | + |
| 77 | +### Three Types of Projects |
| 78 | + |
| 79 | +You can generate three types of projects inside a workspace: |
| 80 | + |
| 81 | +* `lib`-a typescript library |
| 82 | +* `nglib`-an Angular library exporting an NgModule |
| 83 | +* `app`-an Angular application that can be built, served, and shipped to the user |
| 84 | + |
| 85 | +Most of the code in a workspace will be in libs and nglibs. Apps should merely assemble a few nglibs and add some environment-specific parameters. |
| 86 | + |
| 87 | + |
| 88 | + |
| 89 | + |
| 90 | +### Generate an Angular Library |
70 | 91 |
|
71 | 92 | ```bash |
72 | | -ng serve --host 0.0.0.0 --port 4201 |
| 93 | +ng generate nglib shared |
73 | 94 | ``` |
74 | 95 |
|
75 | | -### Generating Components, Directives, Pipes and Services |
| 96 | +Open `libs/shared` to find an empty NgModule. |
| 97 | + |
| 98 | + |
76 | 99 |
|
77 | | -You can use the `ng generate` (or just `ng g`) command to generate Angular components: |
| 100 | + |
| 101 | +### Generate a Component in an NgLibrary |
78 | 102 |
|
79 | 103 | ```bash |
80 | | -ng generate component my-new-component |
81 | | -ng g component my-new-component # using the alias |
82 | | - |
83 | | -# components support relative path generation |
84 | | -# if in the directory src/app/feature/ and you run |
85 | | -ng g component new-cmp |
86 | | -# your component will be generated in src/app/feature/new-cmp |
87 | | -# but if you were to run |
88 | | -ng g component ../newer-cmp |
89 | | -# your component will be generated in src/app/newer-cmp |
90 | | -# if in the directory src/app you can also run |
91 | | -ng g component feature/new-cmp |
92 | | -# and your component will be generated in src/app/feature/new-cmp |
| 104 | +ng generate component logo --lib=shared --module=shared.module.ts --export |
93 | 105 | ``` |
94 | | -You can find all possible blueprints in the table below: |
95 | 106 |
|
96 | | -Scaffold | Usage |
97 | | ---- | --- |
98 | | -[Component](https://github.com/angular/angular-cli/wiki/generate-component) | `ng g component my-new-component` |
99 | | -[Directive](https://github.com/angular/angular-cli/wiki/generate-directive) | `ng g directive my-new-directive` |
100 | | -[Pipe](https://github.com/angular/angular-cli/wiki/generate-pipe) | `ng g pipe my-new-pipe` |
101 | | -[Service](https://github.com/angular/angular-cli/wiki/generate-service) | `ng g service my-new-service` |
102 | | -[Class](https://github.com/angular/angular-cli/wiki/generate-class) | `ng g class my-new-class` |
103 | | -[Guard](https://github.com/angular/angular-cli/wiki/generate-guard) | `ng g guard my-new-guard` |
104 | | -[Interface](https://github.com/angular/angular-cli/wiki/generate-interface) | `ng g interface my-new-interface` |
105 | | -[Enum](https://github.com/angular/angular-cli/wiki/generate-enum) | `ng g enum my-new-enum` |
106 | | -[Module](https://github.com/angular/angular-cli/wiki/generate-module) | `ng g module my-module` |
| 107 | +This will create `LogoComponent` declared and exported from the `SharedModule`. |
| 108 | + |
| 109 | +### Build a Library |
107 | 110 |
|
| 111 | +We can build the library by running the following command: |
108 | 112 |
|
| 113 | +```bash |
| 114 | +ng build shared |
| 115 | +``` |
109 | 116 |
|
| 117 | +### Test a Library |
110 | 118 |
|
111 | | -angular-cli will add reference to `components`, `directives` and `pipes` automatically in the `app.module.ts`. If you need to add this references to another custom module, follow this steps: |
112 | | - |
113 | | - 1. `ng g module new-module` to create a new module |
114 | | - 2. call `ng g component new-module/new-component` |
115 | | - |
116 | | -This should add the new `component`, `directive` or `pipe` reference to the `new-module` you've created. |
117 | | - |
118 | | -### Updating Angular CLI |
| 119 | +We can also test it by running: |
119 | 120 |
|
120 | | -If you're using Angular CLI `1.0.0-beta.28` or less, you need to uninstall `angular-cli` package. It should be done due to changing of package's name and scope from `angular-cli` to `@angular/cli`: |
121 | 121 | ```bash |
122 | | -npm uninstall -g angular-cli |
123 | | -npm uninstall --save-dev angular-cli |
| 122 | +ng test shared |
124 | 123 | ``` |
125 | 124 |
|
126 | | -To update Angular CLI to a new version, you must update both the global package and your project's local package. |
127 | 125 |
|
128 | | -Global package: |
| 126 | + |
| 127 | + |
| 128 | +### Generate an Angular Application |
| 129 | + |
129 | 130 | ```bash |
130 | | -npm uninstall -g @angular/cli |
131 | | -npm cache clean |
132 | | -npm install -g @angular/cli@latest |
| 131 | +ng generate app main |
133 | 132 | ``` |
134 | 133 |
|
135 | | -Local project package: |
| 134 | +Open `libs/shared` to find an empty application. |
| 135 | + |
| 136 | +First, let's add a dependency to the shared library. |
| 137 | + |
| 138 | +Open `apps/main/BUILD.bazel` and add `//libs/shared` to the list of deps, like this: |
| 139 | + |
136 | 140 | ```bash |
137 | | -rm -rf node_modules dist # use rmdir /S/Q node_modules dist in Windows Command Prompt; use rm -r -fo node_modules,dist in Windows PowerShell |
138 | | -npm install --save-dev @angular/cli@latest |
139 | | -npm install |
| 141 | +ng_module( |
| 142 | + name = "module", |
| 143 | + srcs = glob(["**/*.ts"], exclude = ["e2e/**/*.ts"]), |
| 144 | + deps = [ |
| 145 | + '//libs/shared:module' |
| 146 | + ], |
| 147 | + tsconfig = "//:tsconfig.json" |
| 148 | +) |
| 149 | +``` |
| 150 | + |
| 151 | +This tells `Bazel` that if `shared` changes, the `main` application should be rebuilt. |
| 152 | + |
| 153 | + |
| 154 | +Next, open `app.module.ts` and change it to imports `SharedModule`, like this: |
| 155 | + |
| 156 | +```typescript |
| 157 | +import { NgModule } from '@angular/core'; |
| 158 | +import { AppComponent } from './app.component'; |
| 159 | +import { BrowserModule } from '@angular/platform-browser'; |
| 160 | +import { SharedModule } from 'shared'; |
| 161 | + |
| 162 | +@NgModule({ |
| 163 | + imports: [ |
| 164 | + BrowserModule, |
| 165 | + SharedModule |
| 166 | + ], |
| 167 | + declarations: [AppComponent], |
| 168 | + bootstrap: [AppComponent] |
| 169 | +}) |
| 170 | +export class AppModule { } |
140 | 171 | ``` |
141 | 172 |
|
142 | | -If you are updating to 1.0 from a beta or RC version, check out our [1.0 Update Guide](https://github.com/angular/angular-cli/wiki/stories-1.0-update). |
| 173 | +Note that we can use the `shared` library name to import the module. In other words, use relative imports within a library or an application, and absolute imports to import libraries. |
| 174 | + |
| 175 | +Finally, open `app.component.html` and change it to look like this: |
| 176 | + |
| 177 | +```html |
| 178 | +App: |
| 179 | +<app-logo></app-logo> |
| 180 | +``` |
143 | 181 |
|
144 | | -You can find more details about changes between versions in [the Releases tab on GitHub](https://github.com/angular/angular-cli/releases). |
145 | 182 |
|
146 | 183 |
|
147 | | -## Development Hints for working on Angular CLI |
148 | 184 |
|
149 | | -### Working with master |
| 185 | +### Serve an Angular Application |
150 | 186 |
|
151 | 187 | ```bash |
152 | | -git clone https://github.com/angular/angular-cli.git |
153 | | -cd angular-cli |
154 | | -npm link |
| 188 | +ng serve main |
155 | 189 | ``` |
156 | 190 |
|
157 | | -`npm link` is very similar to `npm install -g` except that instead of downloading the package |
158 | | -from the repo, the just cloned `angular-cli/` folder becomes the global package. |
159 | | -Additionally, this repository publishes several packages and we use special logic to load all of them |
160 | | -on development setups. |
| 191 | +Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files. |
| 192 | + |
161 | 193 |
|
162 | | -Any changes to the files in the `angular-cli/` folder will immediately affect the global `@angular/cli` package, |
163 | | -allowing you to quickly test any changes you make to the cli project. |
164 | 194 |
|
165 | | -Now you can use `@angular/cli` via the command line: |
| 195 | +### Build an Application |
| 196 | + |
| 197 | +The following command will build the main application. |
166 | 198 |
|
167 | 199 | ```bash |
168 | | -ng new foo |
169 | | -cd foo |
170 | | -npm link @angular/cli |
171 | | -ng serve |
| 200 | +ng build main |
172 | 201 | ``` |
173 | 202 |
|
174 | | -`npm link @angular/cli` is needed because by default the globally installed `@angular/cli` just loads |
175 | | -the local `@angular/cli` from the project which was fetched remotely from npm. |
176 | | -`npm link @angular/cli` symlinks the global `@angular/cli` package to the local `@angular/cli` package. |
177 | | -Now the `angular-cli` you cloned before is in three places: |
178 | | -The folder you cloned it into, npm's folder where it stores global packages and the Angular CLI project you just created. |
| 203 | +### Test an Application |
179 | 204 |
|
180 | | -You can also use `ng new foo --link-cli` to automatically link the `@angular/cli` package. |
| 205 | +The following command will build the main application. |
181 | 206 |
|
182 | | -Please read the official [npm-link documentation](https://docs.npmjs.com/cli/link) |
183 | | -and the [npm-link cheatsheet](http://browsenpm.org/help#linkinganynpmpackagelocally) for more information. |
| 207 | +```bash |
| 208 | +ng test main |
| 209 | +``` |
184 | 210 |
|
185 | | -To run the Angular CLI test suite use the `node tests/run_e2e.js` command. |
186 | | -It can also receive a filename to only run that test (e.g. `node tests/run_e2e.js tests/e2e/tests/build/dev-build.ts`). |
187 | 211 |
|
188 | | -As part of the test procedure, all packages will be built and linked. |
189 | | -You will need to re-run `npm link` to re-link the development Angular CLI environment after tests finish. |
190 | 212 |
|
| 213 | +## Extra Notes |
191 | 214 |
|
192 | | -## Documentation |
| 215 | +* Read [Building Angular apps at scale](https://medium.com/@Jakeherringbone/building-angular-apps-at-scale-813ef42add04) to understand the advantages of using Bazel. |
| 216 | +* In this branch everything is always built in the AOT mode to make production and dev builds as close as possible. |
193 | 217 |
|
194 | | -The documentation for the Angular CLI is located in this repo's [wiki](https://github.com/angular/angular-cli/wiki). |
195 | 218 |
|
196 | 219 | ## License |
197 | 220 |
|
|
0 commit comments