Skip to content

Commit c2bd3ca

Browse files
chore(Rollup): Improve rollup bundle size -- make externals: rxjs and @angular
1 parent 42b0f16 commit c2bd3ca

File tree

2 files changed

+54
-54
lines changed

2 files changed

+54
-54
lines changed

package.json

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,16 @@
55
"scripts": {
66
"clean": "shx rm -rf lib lib-esm _bundles _dec",
77
"compile": "npm run clean && ngc",
8-
"build": "npm run compile && rollup -c && rollup -c --environment MINIFY",
9-
"test": "karma start config/karma.ng2.js",
8+
"bundle": "rollup -c && rollup -c --environment MINIFY",
9+
"build": "npm run compile && npm run bundle",
1010
"docs": "typedoc --tsconfig tsconfig.typedoc.json --readme README.md --name 'ui-router-ng2' --theme node_modules/ui-router-typedoc-themes/bin/default --out _doc --internal-aliases internal,coreapi,ng2api --external-aliases internalapi,external --navigation-label-globals ui-router-ng2",
1111
"prepublish": "npm run build"
1212
},
1313
"homepage": "https://ui-router.github.io/ng2",
1414
"contributors": [
15-
{
16-
"name": "Nate Abele",
17-
"email": "[email protected]",
18-
"web": "https://radify.io"
19-
},
2015
{
2116
"name": "Chris Thielen",
2217
"web": "https://github.com/christopherthielen"
23-
},
24-
{
25-
"name": "Tim Kindberg",
26-
"web": "https://github.com/timkindberg"
27-
},
28-
{
29-
"name": "Karsten Sperling",
30-
"web": "https://github.com/ksperling"
3118
}
3219
],
3320
"maintainers": [

rollup.config.js

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@ import sourcemaps from 'rollup-plugin-sourcemaps';
55
import visualizer from 'rollup-plugin-visualizer';
66
import commonjs from 'rollup-plugin-commonjs';
77

8-
var MINIFY = process.env.MINIFY;
8+
let MINIFY = process.env.MINIFY;
99

10-
var pkg = require('./package.json');
11-
var banner =
10+
let pkg = require('./package.json');
11+
let banner =
1212
`/**
1313
* ${pkg.description}
1414
* @version v${pkg.version}
1515
* @link ${pkg.homepage}
1616
* @license MIT License, http://www.opensource.org/licenses/MIT
1717
*/`;
1818

19-
var uglifyOpts = { output: {} };
19+
let uglifyOpts = { output: {} };
2020
// retain multiline comment with @license
2121
uglifyOpts.output.comments = (node, comment) =>
2222
comment.type === 'comment2' && /@license/i.test(comment.value);
2323

24-
var plugins = [
24+
let plugins = [
2525
nodeResolve({jsnext: true}),
2626
progress(),
2727
sourcemaps(),
@@ -31,15 +31,7 @@ var plugins = [
3131
if (MINIFY) plugins.push(uglify(uglifyOpts));
3232
if (MINIFY) plugins.push(visualizer({ sourcemap: true }));
3333

34-
var extension = MINIFY ? ".min.js" : ".js";
35-
36-
const BASE_CONFIG = {
37-
sourceMap: true,
38-
format: 'umd',
39-
exports: 'named',
40-
plugins: plugins,
41-
banner: banner,
42-
};
34+
let extension = MINIFY ? '.min.js' : '.js';
4335

4436
// Suppress this error message... there are hundreds of them. Angular team says to ignore it.
4537
// https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
@@ -48,37 +40,58 @@ function onwarn(warning) {
4840
console.error(warning.message);
4941
}
5042

51-
const ROUTER_CONFIG = Object.assign({
43+
function isExternal(id) {
44+
// All rxjs and @angular/* should be external
45+
// except for @angular/router/src/router_config_loader
46+
let externals = [ /^rxjs/, /^@angular\/(?!router\/src\/router_config_loader)/, ];
47+
return externals.map(regex => regex.exec(id)).reduce((acc, val) => acc || !!val, false);
48+
}
49+
50+
const CONFIG = {
5251
moduleName: 'ui-router-ng2',
5352
entry: 'lib/index.js',
5453
dest: '_bundles/ui-router-ng2' + extension,
55-
context: 'undefined',
54+
55+
sourceMap: true,
56+
format: 'umd',
57+
exports: 'named',
58+
plugins: plugins,
59+
banner: banner,
60+
5661
onwarn: onwarn,
57-
external: [
58-
'rxjs',
59-
'rxjs/Rx',
60-
'rxjs/Observable',
61-
'rxjs/ReplaySubject',
62-
'rxjs/BehaviorSubject',
63-
'rxjs/Subscription',
64-
'rxjs/add/observable/of',
65-
'rxjs/add/observable/combineLatest',
66-
'rxjs/add/observable/fromPromise',
67-
'rxjs/add/operator/switchMap',
68-
'rxjs/add/operator/mergeMap',
69-
'rxjs/add/operator/concat',
70-
'rxjs/add/operator/map',
71-
'@angular/core',
72-
'@angular/common',
73-
],
62+
external: isExternal,
63+
7464
globals: {
75-
'@angular/core': 'ng.core',
76-
'@angular/common': 'ng.common',
65+
'rxjs/ReplaySubject': 'Rx',
66+
67+
// Copied these from @angular/router rollup config
68+
'rxjs/BehaviorSubject': 'Rx',
7769
'rxjs/Observable': 'Rx',
7870
'rxjs/Subject': 'Rx',
79-
'rxjs/BehaviorSubject': 'Rx',
80-
'rxjs/ReplaySubject': 'Rx',
71+
'rxjs/Subscription': 'Rx',
72+
'rxjs/util/EmptyError': 'Rx',
73+
74+
'rxjs/observable/from': 'Rx.Observable',
75+
'rxjs/observable/fromPromise': 'Rx.Observable',
76+
'rxjs/observable/forkJoin': 'Rx.Observable',
77+
'rxjs/observable/of': 'Rx.Observable',
78+
79+
'rxjs/operator/toPromise': 'Rx.Observable.prototype',
80+
'rxjs/operator/map': 'Rx.Observable.prototype',
81+
'rxjs/operator/mergeAll': 'Rx.Observable.prototype',
82+
'rxjs/operator/concatAll': 'Rx.Observable.prototype',
83+
'rxjs/operator/mergeMap': 'Rx.Observable.prototype',
84+
'rxjs/operator/reduce': 'Rx.Observable.prototype',
85+
'rxjs/operator/every': 'Rx.Observable.prototype',
86+
'rxjs/operator/first': 'Rx.Observable.prototype',
87+
'rxjs/operator/catch': 'Rx.Observable.prototype',
88+
'rxjs/operator/last': 'Rx.Observable.prototype',
89+
'rxjs/operator/filter': 'Rx.Observable.prototype',
90+
'rxjs/operator/concatMap': 'Rx.Observable.prototype',
91+
92+
'@angular/core': 'ng.core',
93+
'@angular/common': 'ng.common',
8194
}
82-
}, BASE_CONFIG);
95+
};
8396

84-
export default ROUTER_CONFIG;
97+
export default CONFIG;

0 commit comments

Comments
 (0)