|
5 | 5 | ## Overview |
6 | 6 | `ng build` compiles the application into an output directory |
7 | 7 |
|
8 | | -## Options |
9 | | -`--target` (`-t`) define the build target |
| 8 | +### Creating a build |
10 | 9 |
|
11 | | -`--environment` (`-e`) defines the build environment |
| 10 | +```bash |
| 11 | +ng build |
| 12 | +``` |
12 | 13 |
|
13 | | -`--prod` flag to set build target and environment to production |
| 14 | +The build artifacts will be stored in the `dist/` directory. |
14 | 15 |
|
15 | | -`--dev` flag to set build target and environment to development |
| 16 | +### Build Targets and Environment Files |
| 17 | + |
| 18 | +`ng build` can specify both a build target (`--target=production` or `--target=development`) and an |
| 19 | +environment file to be used with that build (`--environment=dev` or `--environment=prod`). |
| 20 | +By default, the development build target and environment are used. |
| 21 | + |
| 22 | +The mapping used to determine which environment file is used can be found in `angular-cli.json`: |
| 23 | + |
| 24 | +```json |
| 25 | +"environments": { |
| 26 | + "source": "environments/environment.ts", |
| 27 | + "dev": "environments/environment.ts", |
| 28 | + "prod": "environments/environment.prod.ts" |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +These options also apply to the serve command. If you do not pass a value for `environment`, |
| 33 | +it will default to `dev` for `development` and `prod` for `production`. |
16 | 34 |
|
17 | 35 | ```bash |
18 | 36 | # these are equivalent |
19 | | ---target=production --environment=prod |
20 | | ---prod --env=prod |
21 | | ---prod |
| 37 | +ng build --target=production --environment=prod |
| 38 | +ng build --prod --env=prod |
| 39 | +ng build --prod |
22 | 40 | # and so are these |
23 | | ---target=development --environment=dev |
24 | | ---dev --e=dev |
25 | | ---dev |
| 41 | +ng build --target=development --environment=dev |
| 42 | +ng build --dev --e=dev |
| 43 | +ng build --dev |
26 | 44 | ng build |
27 | 45 | ``` |
28 | 46 |
|
| 47 | +You can also add your own env files other than `dev` and `prod` by doing the following: |
| 48 | +- create a `src/environments/environment.NAME.ts` |
| 49 | +- add `{ "NAME": 'src/environments/environment.NAME.ts' }` to the `apps[0].environments` object in `angular-cli.json` |
| 50 | +- use them via the `--env=NAME` flag on the build/serve commands. |
| 51 | + |
| 52 | +### Base tag handling in index.html |
| 53 | + |
| 54 | +When building you can modify base tag (`<base href="/">`) in your index.html with `--base-href your-url` option. |
| 55 | + |
| 56 | +```bash |
| 57 | +# Sets base tag href to /myUrl/ in your index.html |
| 58 | +ng build --base-href /myUrl/ |
| 59 | +ng build --bh /myUrl/ |
| 60 | +``` |
| 61 | + |
| 62 | +### Bundling |
| 63 | + |
| 64 | +All builds make use of bundling, and using the `--prod` flag in `ng build --prod` |
| 65 | +or `ng serve --prod` will also make use of uglifying and tree-shaking functionality. |
| 66 | + |
| 67 | +## Options |
| 68 | +`--target` (`-t`) define the build target |
| 69 | + |
| 70 | +`--environment` (`-e`) defines the build environment |
| 71 | + |
| 72 | +`--prod` flag to set build target and environment to production |
| 73 | + |
| 74 | +`--dev` flag to set build target and environment to development |
| 75 | + |
29 | 76 | `--output-path` (`-o`) path where output will be placed |
30 | 77 |
|
31 | 78 | `--output-hashing` define the output filename cache-busting hashing mode |
|
0 commit comments