mirror of
https://github.com/angular/angular-cli.git
synced 2025-05-16 18:43:42 +08:00
docs: cleanup build command wiki entry for 6.0
This commit is contained in:
parent
c9a46eb520
commit
74bac97ce0
@ -15,43 +15,7 @@ The build artifacts will be stored in the `dist/` directory.
|
||||
|
||||
All commands that build or serve your project, `ng build/serve/e2e`, will delete the output
|
||||
directory (`dist/` by default).
|
||||
This can be disabled via the `--no-delete-output-path` (or `--delete-output-path=false`) flag.
|
||||
|
||||
### Build Targets and Environment Files
|
||||
|
||||
`ng build` can specify both a build target (`--target=production` or `--target=development`) and an
|
||||
environment file to be used with that build (`--environment=dev` or `--environment=prod`).
|
||||
By default, the development build target and environment are used.
|
||||
|
||||
The mapping used to determine which environment file is used can be found in `.angular-cli.json`:
|
||||
|
||||
```json
|
||||
"environmentSource": "environments/environment.ts",
|
||||
"environments": {
|
||||
"dev": "environments/environment.ts",
|
||||
"prod": "environments/environment.prod.ts"
|
||||
}
|
||||
```
|
||||
|
||||
These options also apply to the serve command. If you do not pass a value for `environment`,
|
||||
it will default to `dev` for `development` and `prod` for `production`.
|
||||
|
||||
```bash
|
||||
# these are equivalent
|
||||
ng build --target=production --environment=prod
|
||||
ng build --prod --env=prod
|
||||
ng build --prod
|
||||
# and so are these
|
||||
ng build --target=development --environment=dev
|
||||
ng build --dev --e=dev
|
||||
ng build --dev
|
||||
ng build
|
||||
```
|
||||
|
||||
You can also add your own env files other than `dev` and `prod` by doing the following:
|
||||
- create a `src/environments/environment.NAME.ts`
|
||||
- add `{ "NAME": 'src/environments/environment.NAME.ts' }` to the `apps[0].environments` object in `.angular-cli.json`
|
||||
- use them via the `--env=NAME` flag on the build/serve commands.
|
||||
This can be disabled via the `--delete-output-path=false` option.
|
||||
|
||||
### Base tag handling in index.html
|
||||
|
||||
@ -60,7 +24,6 @@ When building you can modify base tag (`<base href="/">`) in your index.html wit
|
||||
```bash
|
||||
# Sets base tag href to /myUrl/ in your index.html
|
||||
ng build --base-href /myUrl/
|
||||
ng build --bh /myUrl/
|
||||
```
|
||||
|
||||
### Bundling & Tree-Shaking
|
||||
@ -68,26 +31,6 @@ ng build --bh /myUrl/
|
||||
All builds make use of bundling and limited tree-shaking, while `--prod` builds also run limited
|
||||
dead code elimination via UglifyJS.
|
||||
|
||||
### `--dev` vs `--prod` builds
|
||||
|
||||
Both `--dev`/`--target=development` and `--prod`/`--target=production` are 'meta' flags, that set other flags.
|
||||
If you do not specify either you will get the `--dev` defaults.
|
||||
|
||||
Flag | `--dev` | `--prod`
|
||||
--- | --- | ---
|
||||
`--aot` | `false` | `true`
|
||||
`--environment` | `dev` | `prod`
|
||||
`--output-hashing` | `media` | `all`
|
||||
`--sourcemaps` | `true` | `false`
|
||||
`--extract-css` | `false` | `true`
|
||||
`--named-chunks` | `true` | `false`
|
||||
`--build-optimizer` | `false` | `true` with AOT and Angular 5
|
||||
|
||||
`--prod` also sets the following non-flaggable settings:
|
||||
- Adds service worker if configured in `.angular-cli.json`.
|
||||
- Replaces `process.env.NODE_ENV` in modules with the `production` value (this is needed for some libraries, like react).
|
||||
- Runs UglifyJS on the code.
|
||||
|
||||
### `--build-optimizer` and `--vendor-chunk`
|
||||
|
||||
When using Build Optimizer the vendor chunk will be disabled by default.
|
||||
@ -104,20 +47,6 @@ If a resource is less than 10kb it will also be inlined.
|
||||
|
||||
You'll see these resources be outputted and fingerprinted at the root of `dist/`.
|
||||
|
||||
### Service Worker
|
||||
|
||||
There is experimental service worker support for production builds available in the CLI.
|
||||
To enable it, run the following commands:
|
||||
```
|
||||
npm install @angular/service-worker --save
|
||||
ng set apps.0.serviceWorker=true
|
||||
```
|
||||
|
||||
On `--prod` builds a service worker manifest will be created and loaded automatically.
|
||||
Remember to disable the service worker while developing to avoid stale code.
|
||||
|
||||
Note: service worker support is experimental and subject to change.
|
||||
|
||||
### ES2015 support
|
||||
|
||||
To build in ES2015 mode, edit `./tsconfig.json` to use `"target": "es2015"` (instead of `es5`).
|
||||
|
Loading…
x
Reference in New Issue
Block a user