You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*[Development Hints for hacking on Angular CLI](#development-hints-for-hacking-on-angular-cli)
42
+
*[License](#license)
57
43
58
44
## Installation
59
45
@@ -112,284 +98,6 @@ Interface | `ng g interface my-new-interface`
112
98
Enum | `ng g enum my-new-enum`
113
99
Module | `ng g module my-module`
114
100
115
-
### Generating a route
116
-
117
-
The CLI supports routing in several ways:
118
-
119
-
- We include the `@angular/router` NPM package when creating or initializing a project.
120
-
121
-
- When you generate a module, you can use the `--routing` option like `ng g module my-module --routing` to create a separate file `my-module-routing.module.ts` to store the module routes.
122
-
123
-
The file includes an empty `Routes` object that you can fill with routes to different components and/or modules.
124
-
125
-
The `--routing` option also generates a default component with the same name as the module.
126
-
127
-
- You can use the `--routing` option with `ng new` to create a `app-routing.module.ts` file when you create or initialize a project.
128
-
129
-
<!-- DeleteSection1 Start here to remove upon next release -->
130
-
### Creating a build
131
-
132
-
```bash
133
-
ng build
134
-
```
135
-
136
-
The build artifacts will be stored in the `dist/` directory.
137
-
138
-
### Build Targets and Environment Files
139
-
140
-
`ng build` can specify both a build target (`--target=production` or `--target=development`) and an
141
-
environment file to be used with that build (`--environment=dev` or `--environment=prod`).
142
-
By default, the development build target and environment are used.
143
-
144
-
The mapping used to determine which environment file is used can be found in `angular-cli.json`:
145
-
146
-
```json
147
-
"environments": {
148
-
"source": "environments/environment.ts",
149
-
"dev": "environments/environment.ts",
150
-
"prod": "environments/environment.prod.ts"
151
-
}
152
-
```
153
-
154
-
These options also apply to the serve command. If you do not pass a value for `environment`,
155
-
it will default to `dev` for `development` and `prod` for `production`.
156
-
157
-
```bash
158
-
# these are equivalent
159
-
ng build --target=production --environment=prod
160
-
ng build --prod --env=prod
161
-
ng build --prod
162
-
# and so are these
163
-
ng build --target=development --environment=dev
164
-
ng build --dev --e=dev
165
-
ng build --dev
166
-
ng build
167
-
```
168
-
169
-
You can also add your own env files other than `dev` and `prod` by doing the following:
170
-
- create a `src/environments/environment.NAME.ts`
171
-
- add `{ "NAME": 'src/environments/environment.NAME.ts' }` to the `apps[0].environments` object in `angular-cli.json`
172
-
- use them via the `--env=NAME` flag on the build/serve commands.
173
-
174
-
### Base tag handling in index.html
175
-
176
-
When building you can modify base tag (`<base href="/">`) in your index.html with `--base-href your-url` option.
177
-
178
-
```bash
179
-
# Sets base tag href to /myUrl/ in your index.html
180
-
ng build --base-href /myUrl/
181
-
ng build --bh /myUrl/
182
-
```
183
-
184
-
### Bundling
185
-
186
-
All builds make use of bundling, and using the `--prod` flag in `ng build --prod`
187
-
or `ng serve --prod` will also make use of uglifying and tree-shaking functionality.
188
-
189
-
### Running unit tests
190
-
191
-
```bash
192
-
ng test
193
-
```
194
-
195
-
Tests will execute after a build is executed via [Karma](http://karma-runner.github.io/0.13/index.html), and it will automatically watch your files for changes. You can run tests a single time via `--watch=false` or `--single-run`.
196
-
197
-
You can run tests with coverage via `--code-coverage`. The coverage report will be in the `coverage/` directory.
198
-
199
-
### Running end-to-end tests
200
-
201
-
```bash
202
-
ng e2e
203
-
```
204
-
205
-
Before running the tests make sure you are serving the app via `ng serve`.
206
-
207
-
End-to-end tests are run via [Protractor](https://angular.github.io/protractor/).
208
-
209
-
### Proxy To Backend
210
-
Using the proxying support in webpack's dev server we can highjack certain urls and send them to a backend server.
211
-
We do this by passing a file to `--proxy-config`
212
-
213
-
Say we have a server running on `http://localhost:3000/api` and we want all calls to `http://localhost:4200/api` to go to that server.
214
-
215
-
We create a file next to projects `package.json` called `proxy.conf.json`
216
-
with the content
217
-
218
-
```json
219
-
{
220
-
"/api": {
221
-
"target": "http://localhost:3000",
222
-
"secure": false
223
-
}
224
-
}
225
-
```
226
-
227
-
You can read more about what options are available here [webpack-dev-server proxy settings](https://webpack.github.io/docs/webpack-dev-server.html#proxy)
228
-
229
-
and then we edit the `package.json` file's start script to be
- We include the `@angular/router` NPM package when creating or initializing a project.
6
+
7
+
- When you generate a module, you can use the `--routing` option like `ng g module my-module --routing` to create a separate file `my-module-routing.module.ts` to store the module routes.
8
+
9
+
The file includes an empty `Routes` object that you can fill with routes to different components and/or modules.
10
+
11
+
The `--routing` option also generates a default component with the same name as the module.
12
+
13
+
- You can use the `--routing` option with `ng new` to create a `app-routing.module.ts` file when you create or initialize a project.
0 commit comments