Skip to content

Commit b74d609

Browse files
committed
feat(build): update angular-cli.json
1 parent 504a497 commit b74d609

27 files changed

+315
-161
lines changed

README.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ The generated project has dependencies that require **Node 4 or greater**.
3636
* [Creating a Build](#creating-a-build)
3737
* [Build Targets and Environment Files](#build-targets-and-environment-files)
3838
* [Bundling](#bundling)
39+
* [Adding extra files to the build](#adding-extra-files-to-the-build)
3940
* [Running Unit Tests](#running-unit-tests)
4041
* [Running End-to-End Tests](#running-end-to-end-tests)
4142
* [Deploying the App via GitHub Pages](#deploying-the-app-via-github-pages)
@@ -124,8 +125,8 @@ A build can specify both a build target (`development` or `production`) and an
124125
environment file to be used with that build. By default, the development build
125126
target is used.
126127

127-
At build time, `src/app/environments/environment.ts` will be replaced by
128-
`src/app/environments/environment.{NAME}.ts` where `NAME` is the argument
128+
At build time, `src/environments/environment.ts` will be replaced by
129+
`src/environments/environment.NAME.ts` where `NAME` is the argument
129130
provided to the `--environment` flag.
130131

131132
These options also apply to the serve command. If you do not pass a value for `environment`,
@@ -143,14 +144,49 @@ ng build --dev
143144
ng build
144145
```
145146

146-
You can also add your own env files other than `dev` and `prod` by creating a
147-
`src/app/environments/environment.{NAME}.ts` and use them by using the `--env=NAME`
148-
flag on the build/serve commands.
147+
You can also add your own env files other than `dev` and `prod` by doing the following:
148+
- create a `src/environments/environment.NAME.ts`
149+
- add `{ NAME: 'src/environments/environment.NAME.ts' }` to the the `apps[0].environments` object in `angular-cli.json`
150+
- use them by using the `--env=NAME` flag on the build/serve commands.
149151

150152
### Bundling
151153

152-
Builds created with the `-prod` flag via `ng build -prod` or `ng serve -prod` bundle
153-
all dependencies into a single file, and make use of tree-shaking techniques.
154+
All builds make use of bundling, and using the `-prod` flag in `ng build -prod`
155+
or `ng serve -prod` will also make use of uglifying and tree-shaking functionality.
156+
157+
### Adding extra files to the build
158+
159+
The `apps[0].additionalEntries` array in `angular-cli.json` allows a user to add more files to the build.
160+
161+
The `additionalEntries` array supports two kinds of entries, with different behaviours.
162+
- strings will be bundled together with the `main` bundle
163+
- objects with `input` and `output` properties will create a new bundle which is loaded before the `main` bundle.
164+
165+
By default it looks like this:
166+
167+
```
168+
apps: [
169+
{
170+
//...
171+
"additionalEntries": [
172+
{ "input": "polyfills.ts", "output": "polyfills.js" },
173+
"scripts.ts",
174+
"styles.css"
175+
],
176+
}
177+
]
178+
```
179+
180+
These entries correspond to the following files in `src/`:
181+
- `polifills.ts` has browser polyfills needed for Angular 2. It will be
182+
bundled separately as `polyfills.js` and loaded before everything else.
183+
- `styles.css` allows users to add global styles and supports
184+
[CSS imports](https://developer.mozilla.org/en/docs/Web/CSS/@import). If the
185+
project is created with the `--style=sass` option, this will be a `.sass` file
186+
instead, and the same applies to `scss/less/styl`. It will be part of the main
187+
bundle.
188+
- `scripts.ts` allows users to add global code outside of the Angular 2 app. It
189+
will also be part of the main bundle.
154190

155191
### Running unit tests
156192

addon/ng2/blueprints/component/index.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ module.exports = {
2525

2626
var defaultPrefix = '';
2727
if (this.project.ngConfig &&
28-
this.project.ngConfig.defaults &&
29-
this.project.ngConfig.defaults.prefix) {
30-
defaultPrefix = this.project.ngConfig.defaults.prefix + '-';
28+
this.project.ngConfig.apps[0] &&
29+
this.project.ngConfig.apps[0].prefix) {
30+
defaultPrefix = this.project.ngConfig.apps[0].prefix + '-';
3131
}
3232
var prefix = this.options.prefix ? defaultPrefix : '';
3333
this.selector = stringUtils.dasherize(prefix + parsedPath.name);
@@ -97,7 +97,7 @@ module.exports = {
9797
dir = dirParts.join(path.sep);
9898
}
9999
}
100-
var srcDir = this.project.ngConfig.defaults.sourceDir;
100+
var srcDir = this.project.ngConfig.apps[0].root;
101101
this.appDir = dir.substr(dir.indexOf(srcDir) + srcDir.length);
102102
this.generatePath = dir;
103103
return dir;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
export * from './environments/environment';
21
export * from './app.component';
32
export * from './app.module';

addon/ng2/blueprints/ng2/files/__path__/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
22
import { enableProdMode } from '@angular/core';
3-
import { AppModule, environment } from './app/';
3+
import { environment } from './environments/environment';
4+
import { AppModule } from './app/';
45

56
if (environment.production) {
67
enableProdMode();

addon/ng2/blueprints/ng2/files/__path__/polyfills.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Prefer CoreJS over the polyfills above
1+
// This file includes polyfills needed by Angular 2 and is loaded before
2+
// the app. You can add your own extra polyfills to this file.
23
import 'core-js/es6/symbol';
34
import 'core-js/es6/object';
45
import 'core-js/es6/function';
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// You can add additional imports to this file and
2+
// they will be loaded before your app

0 commit comments

Comments
 (0)