X Tutup
Skip to content

Commit 1c779d8

Browse files
docs(bundles): document existing bundles and their usage
Closes angular#5777 Closes angular#5878
1 parent a79fe05 commit 1c779d8

File tree

2 files changed

+83
-1
lines changed

2 files changed

+83
-1
lines changed

gulpfile.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,10 @@ gulp.task('!bundle.testing', ['build.js.dev'], function() {
11131113
{sourceMaps: true});
11141114
});
11151115

1116+
gulp.task('!bundles.js.docs', function() {
1117+
gulp.src('modules/angular2/docs/bundles/*').pipe(gulp.dest('dist/js/bundle'));
1118+
});
1119+
11161120
gulp.task('!bundles.js.umd', ['build.js.dev'], function() {
11171121
var q = require('q');
11181122
var webpack = q.denodeify(require('webpack'));
@@ -1252,7 +1256,8 @@ gulp.task('bundles.js',
12521256
'!bundle.web_worker.js.dev.deps',
12531257
'bundles.js.umd.min',
12541258
'!bundle.testing',
1255-
'!bundle.ng.polyfills'
1259+
'!bundle.ng.polyfills',
1260+
'!bundles.js.docs'
12561261
],
12571262
function(done) { runSequence('!bundle.copy', '!bundles.js.checksize', done); });
12581263

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# TL;DR;
2+
3+
* If you write ES5 use _one_ of the `UMD` bundles.
4+
* If you experiment with Angular2 using online prototyping tools like [plnkr](http://plnkr.co/) or similar use `System.register` bundles with SystemJS loader.
5+
* If you use build tools like Browserify or WebPack - bundle Angular2 as part of your build.
6+
* For all the above cases you must use `angular2-polyfills.js` in a `script` tag to easily include polyfills and external dependencies.
7+
8+
# Modules, barrels and bundles
9+
10+
Angular2 source code is authored using the ES2015 standardized module format where one module corresponds to exactly one file. Multiple modules (files) can be logically grouped into so-called "barrels".
11+
A bundle is a file the contains all the code for one or more barrels.
12+
13+
Most bundles come in several flavors:
14+
* regular and minified (got `.min` in their name);
15+
* regular and "development" (have `.dev` in their name) - "development" bundles contain in-line source maps and don't have minified flavor (minification removes in-lined source maps).
16+
17+
# Bundles, their content and usage scenarios
18+
19+
Angular 2 distributes several types of bundles targeted at specific usages:
20+
* users writing ES5 code without any transpilation steps
21+
* users experimenting with Angular 2 and TypeScript/ES2015 using online tools like plunker, jsbin or similar
22+
23+
Since each identified scenario has slightly different requirements and constraints there are specific bundles for each use-case.
24+
25+
## ES5 and ngUpgrade users
26+
27+
ES5 users and AngularJS 1.x users interested in the `ngUpgrade` path can take advantage of the bundles in the [UMD format](https://github.com/umdjs/umd).
28+
Those are coarse-grained bundles that combine many barrels in one final file.
29+
30+
filename | list of barrels | dev/prod | minified?
31+
------------|-------------------|----------|-------------|--------------|-------------
32+
`angular2.umd.js` | `RxJS`, `angular2/core`, `angular2/common`, `angular2/compiler`, `angular2/platform/browser`, `angular2/platform/common_dom`, `angular2/http`, `angular2/router`, `angular2/instrumentation`, `angular2/upgrade`| prod | no
33+
`angular2.umd.min.js` | `RxJS`, `angular2/core`, `angular2/common`, `angular2/compiler`, `angular2/platform/browser`, `angular2/platform/common_dom`, `angular2/http`, `angular2/router`, `angular2/instrumentation`, `angular2/upgrade` | prod | yes
34+
`angular2.umd.dev.js` | `RxJS`, `angular2/core`, `angular2/common`, `angular2/compiler`, `angular2/platform/browser`, `angular2/platform/common_dom`, `angular2/http`, `angular2/router`, `angular2/instrumentation`, `angular2/upgrade` | dev | no
35+
`angular2-testing.umd.dev.js` | `RxJS`, `angular2/core`, `angular2/common`, `angular2/compiler`, `angular2/platform/browser`, `angular2/platform/common_dom`, `angular2/http`, `angular2/router`, `angular2/instrumentation`, `angular2/upgrade`, `angular2/testing`, `angular2/http/testing`, `angular2/router/testing` | dev | no
36+
37+
**Warning**: bundles in the `UMD` format are _not_ "additive". A single application should use only one bundle from the above list.
38+
39+
## SystemJS loader users
40+
41+
[SystemJS loader](https://github.com/systemjs/systemjs) with on-the-fly (in a browser) transpilations support is very useful for quick experiments using tools like plunker, jsbin or similar.
42+
For this scenario Angular 2 is distributed with bundles in the [System.register format](https://github.com/ModuleLoader/es6-module-loader/wiki/System.register-Explained):
43+
44+
filename | list of barrels | dev/prod | minified?
45+
------------|-------------------|----------|-------------|--------------|-------------
46+
`angular2.js` | `RxJS`, `angular2/core`, `angular2/common`, `angular2/compiler`, `angular2/platform/browser`, `angular2/platform/common_dom`, `angular2/instrumentation`| prod | no
47+
`angular2.min.js` | `RxJS`, `angular2/core`, `angular2/common`, `angular2/compiler`, `angular2/platform/browser`, `angular2/platform/common_dom`, `angular2/instrumentation`| prod | yes
48+
`angular2.dev.js` | `RxJS`, `angular2/core`, `angular2/common`, `angular2/compiler`, `angular2/platform/browser`, `angular2/platform/common_dom`, `angular2/instrumentation`| dev | no
49+
`http.js` | `angular2/http` | prod | no
50+
`http.min.js` | `angular2/http` | prod | yes
51+
`http.dev.js` | `angular2/http` | dev | no
52+
`router.js` | `angular2/router` | prod | no
53+
`router.min.js` | `angular2/router` | prod | yes
54+
`router.dev.js` | `angular2/router` | dev | no
55+
`upgrade.js` | `angular2/upgrade` | prod | no
56+
`upgrade.min.js` | `angular2/upgrade` | prod | yes
57+
`upgrade.dev.js` | `angular2/upgrade` | dev | no
58+
`testing.dev.js` | `angular2/testing`, `angular2/http/testing`, `angular2/router/testing` | dev | no
59+
60+
**Note**: bundles in the `System.register` format are "additive" - it is quite common to include several bundles in one application.
61+
For example people using Angular 2 with `http` and `router` would include: `angular2.js`, `http.js` and `router.js`.
62+
63+
## Browserify / JSPM / Rollup / WebPack users
64+
65+
Angular 2 doesn't provide any bundles for use with packaging tools Browserify or WebPack. Those tools are sophisticated enough to build optimal bundles for production use from individual Angular 2 files distributed in the npm package.
66+
An example of an Angular 2 project built with WebPack can be found in the [angular2-seed](https://github.com/angular/angular2-seed) repository.
67+
68+
# Polyfills and external dependencies
69+
70+
Polyfills are required for Angular 2 to function properly (the exact list depends on the browser used) and external dependencies ([zone.js](https://github.com/angular/zone.js)).
71+
To ease setup of Angular 2 applications there is one file - `angular2-polyfills.js` - that combines:
72+
* a pollyfill mandatory for all browsers: [reflect-metadata](https://www.npmjs.com/package/reflect-metadata)
73+
* [zone.js](https://github.com/angular/zone.js)
74+
75+
**Note**: `angular2-polyfills.js` contains code that should be loaded into the browser as the very first code of the web application even before the module loader. The preferred solution is to load the mentioned file in a `script` tag as early as possible.
76+
77+
Users of pre-ES6 browsers might need to add an ES6 shim (e.g. [es6-shim](https://github.com/paulmillr/es6-shim))

0 commit comments

Comments
 (0)
X Tutup