Skip to content

Commit

Permalink
chore(Rollup): Improve rollup bundle size -- make externals: rxjs and @…
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Jan 22, 2017
1 parent 42b0f16 commit c2bd3ca
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
17 changes: 2 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,16 @@
"scripts": {
"clean": "shx rm -rf lib lib-esm _bundles _dec",
"compile": "npm run clean && ngc",
"build": "npm run compile && rollup -c && rollup -c --environment MINIFY",
"test": "karma start config/karma.ng2.js",
"bundle": "rollup -c && rollup -c --environment MINIFY",
"build": "npm run compile && npm run bundle",
"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",
"prepublish": "npm run build"
},
"homepage": "https://ui-router.github.io/ng2",
"contributors": [
{
"name": "Nate Abele",
"email": "[email protected]",
"web": "https://radify.io"
},
{
"name": "Chris Thielen",
"web": "https://github.com/christopherthielen"
},
{
"name": "Tim Kindberg",
"web": "https://github.com/timkindberg"
},
{
"name": "Karsten Sperling",
"web": "https://github.com/ksperling"
}
],
"maintainers": [
Expand Down
91 changes: 52 additions & 39 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ import sourcemaps from 'rollup-plugin-sourcemaps';
import visualizer from 'rollup-plugin-visualizer';
import commonjs from 'rollup-plugin-commonjs';

var MINIFY = process.env.MINIFY;
let MINIFY = process.env.MINIFY;

var pkg = require('./package.json');
var banner =
let pkg = require('./package.json');
let banner =
`/**
* ${pkg.description}
* @version v${pkg.version}
* @link ${pkg.homepage}
* @license MIT License, http://www.opensource.org/licenses/MIT
*/`;

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

var plugins = [
let plugins = [
nodeResolve({jsnext: true}),
progress(),
sourcemaps(),
Expand All @@ -31,15 +31,7 @@ var plugins = [
if (MINIFY) plugins.push(uglify(uglifyOpts));
if (MINIFY) plugins.push(visualizer({ sourcemap: true }));

var extension = MINIFY ? ".min.js" : ".js";

const BASE_CONFIG = {
sourceMap: true,
format: 'umd',
exports: 'named',
plugins: plugins,
banner: banner,
};
let extension = MINIFY ? '.min.js' : '.js';

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

const ROUTER_CONFIG = Object.assign({
function isExternal(id) {
// All rxjs and @angular/* should be external
// except for @angular/router/src/router_config_loader
let externals = [ /^rxjs/, /^@angular\/(?!router\/src\/router_config_loader)/, ];
return externals.map(regex => regex.exec(id)).reduce((acc, val) => acc || !!val, false);
}

const CONFIG = {
moduleName: 'ui-router-ng2',
entry: 'lib/index.js',
dest: '_bundles/ui-router-ng2' + extension,
context: 'undefined',

sourceMap: true,
format: 'umd',
exports: 'named',
plugins: plugins,
banner: banner,

onwarn: onwarn,
external: [
'rxjs',
'rxjs/Rx',
'rxjs/Observable',
'rxjs/ReplaySubject',
'rxjs/BehaviorSubject',
'rxjs/Subscription',
'rxjs/add/observable/of',
'rxjs/add/observable/combineLatest',
'rxjs/add/observable/fromPromise',
'rxjs/add/operator/switchMap',
'rxjs/add/operator/mergeMap',
'rxjs/add/operator/concat',
'rxjs/add/operator/map',
'@angular/core',
'@angular/common',
],
external: isExternal,

globals: {
'@angular/core': 'ng.core',
'@angular/common': 'ng.common',
'rxjs/ReplaySubject': 'Rx',

// Copied these from @angular/router rollup config
'rxjs/BehaviorSubject': 'Rx',
'rxjs/Observable': 'Rx',
'rxjs/Subject': 'Rx',
'rxjs/BehaviorSubject': 'Rx',
'rxjs/ReplaySubject': 'Rx',
'rxjs/Subscription': 'Rx',
'rxjs/util/EmptyError': 'Rx',

'rxjs/observable/from': 'Rx.Observable',
'rxjs/observable/fromPromise': 'Rx.Observable',
'rxjs/observable/forkJoin': 'Rx.Observable',
'rxjs/observable/of': 'Rx.Observable',

'rxjs/operator/toPromise': 'Rx.Observable.prototype',
'rxjs/operator/map': 'Rx.Observable.prototype',
'rxjs/operator/mergeAll': 'Rx.Observable.prototype',
'rxjs/operator/concatAll': 'Rx.Observable.prototype',
'rxjs/operator/mergeMap': 'Rx.Observable.prototype',
'rxjs/operator/reduce': 'Rx.Observable.prototype',
'rxjs/operator/every': 'Rx.Observable.prototype',
'rxjs/operator/first': 'Rx.Observable.prototype',
'rxjs/operator/catch': 'Rx.Observable.prototype',
'rxjs/operator/last': 'Rx.Observable.prototype',
'rxjs/operator/filter': 'Rx.Observable.prototype',
'rxjs/operator/concatMap': 'Rx.Observable.prototype',

'@angular/core': 'ng.core',
'@angular/common': 'ng.common',
}
}, BASE_CONFIG);
};

export default ROUTER_CONFIG;
export default CONFIG;

0 comments on commit c2bd3ca

Please sign in to comment.