Skip to content

Commit

Permalink
feat(*): bundle using rollupjs for smaller bundle and faster init times
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen committed Dec 14, 2016
1 parent a51f1de commit a4b5500
Show file tree
Hide file tree
Showing 5 changed files with 108 additions and 23 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"clean": "shx rm -rf lib lib-esm _doc build release *.log",
"build": "tsc && tsc -m es6 --outDir lib-esm && npm run fixdts",
"fixdts": "dts-downlevel 'lib/**/*.d.ts' 'lib-esm/**/*.d.ts'",
"package": "npm run clean && npm run build && webpack --hide-modules",
"package": "npm run clean && npm run build && npm run bundle",
"bundle": "npm run bundle_router && npm run bundle_events && npm run bundle_resolve",
"bundle_router": "rollup -c --environment ROUTER && rollup -c --environment ROUTER,MINIFY",
"bundle_events": "rollup -c --environment EVENTS && rollup -c --environment EVENTS,MINIFY",
"bundle_resolve": "rollup -c --environment RESOLVE && rollup -c --environment RESOLVE,MINIFY",
"test": "npm run test:integrate",
"test:ng12": "karma start --ngversion 1.2.28",
"test:ng13": "karma start --ngversion 1.3.16",
Expand Down Expand Up @@ -89,6 +93,9 @@
"lodash": "^4.5.1",
"remap-istanbul": "^0.6.3",
"replace-in-file": "^2.0.3",
"rollup": "^0.37.0",
"rollup-plugin-node-resolve": "^2.0.0",
"rollup-plugin-uglify": "^1.0.1",
"shelljs": "^0.7.0",
"shx": "^0.1.4",
"systemjs": "^0.18.4",
Expand Down
63 changes: 63 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import uglify from 'rollup-plugin-uglify';

var MINIFY = process.env.MINIFY;
var ROUTER = process.env.ROUTER;
var EVENTS = process.env.EVENTS;
var RESOLVE = process.env.RESOLVE;

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

var uglifyOpts = { output: {} };
// retain multiline comment with @license
uglifyOpts.output.comments = (node, comment) =>
comment.type === 'comment2' && /@license/i.test(comment.value);
var plugins = (MINIFY ? [uglify(uglifyOpts)] : []).concat(nodeResolve({jsnext: true}));

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

const BASE_CONFIG = {
sourceMap: true,
format: 'umd',
exports: 'named',
plugins: plugins,
banner: banner,
};

const ROUTER_CONFIG = Object.assign({
moduleName: 'angular-ui-router',
entry: 'lib-esm/index.js',
dest: 'release/angular-ui-router' + extension,
globals: { angular: 'angular' },
external: 'angular',
}, BASE_CONFIG);

const EVENTS_CONFIG = Object.assign({}, BASE_CONFIG, {
moduleName: 'angular-ui-router-state-events',
entry: 'lib-esm/legacy/stateEvents.js',
dest: 'release/stateEvents' + extension,
globals: { angular: 'angular', 'ui-router-core': 'ui-router-core' },
external: ['angular', 'ui-router-core'],
});

const RESOLVE_CONFIG = Object.assign({}, BASE_CONFIG, {
moduleName: 'angular-ui-router-resolve-service',
entry: 'lib-esm/legacy/resolveService.js',
dest: 'release/resolveService' + extension,
globals: { angular: 'angular', 'ui-router-core': 'ui-router-core' },
external: ['angular', 'ui-router-core'],
});

const CONFIG =
RESOLVE ? RESOLVE_CONFIG :
EVENTS ? EVENTS_CONFIG :
ROUTER ? ROUTER_CONFIG : ROUTER_CONFIG;

export default CONFIG;
5 changes: 3 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/**
* Main entry point for angular 1.x build
* @module ng1
*/
/** for typedoc */
*/ /** */

import * as core from "ui-router-core";
export { core };
export * from "ui-router-core";

export * from "./interface";
Expand Down
3 changes: 0 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// <package>/../../src/ is copied to <package>/src
// This config is then copied to <package>/src/webpack.config.js

var pkg = require('./package.json');
var banner = pkg.description + '\n' +
'@version v' + pkg.version + '\n' +
Expand Down
51 changes: 34 additions & 17 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,6 @@ ast-types@0.8.12:
version "0.8.12"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.8.12.tgz#a0d90e4351bb887716c83fd637ebf818af4adfcc"

ast-types@0.8.15:
version "0.8.15"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.8.15.tgz#8eef0827f04dff0ec8857ba925abe3fea6194e52"

ast-types@0.9.2:
version "0.9.2"
resolved "https://registry.yarnpkg.com/ast-types/-/ast-types-0.9.2.tgz#2cc19979d15c655108bf565323b8e7ee38751f6b"
Expand Down Expand Up @@ -506,6 +502,12 @@ breakable@~1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/breakable/-/breakable-1.0.0.tgz#784a797915a38ead27bad456b5572cb4bbaa78c1"

browser-resolve@^1.11.0:
version "1.11.2"
resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.2.tgz#8ff09b0a2c421718a1051c260b32e48f442938ce"
dependencies:
resolve "1.1.7"

browserify-aes@0.4.0:
version "0.4.0"
resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-0.4.0.tgz#067149b668df31c4b58533e02d01e806d8608e2c"
Expand All @@ -530,7 +532,7 @@ buffer@^4.9.0:
ieee754 "^1.1.4"
isarray "^1.0.0"

builtin-modules@^1.0.0:
builtin-modules@^1.0.0, builtin-modules@^1.1.0:
version "1.1.1"
resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f"

Expand Down Expand Up @@ -1264,6 +1266,10 @@ expand-range@^1.8.1:
dependencies:
fill-range "^2.1.0"

expose-loader@^0.7.1:
version "0.7.1"
resolved "https://registry.yarnpkg.com/expose-loader/-/expose-loader-0.7.1.tgz#411ee89443aa682f8ea9d9111accf41bfd7e94d9"

express@^4.13.3:
version "4.14.0"
resolved "https://registry.yarnpkg.com/express/-/express-4.14.0.tgz#c1ee3f42cdc891fb3dc650a8922d51ec847d0d66"
Expand Down Expand Up @@ -2977,7 +2983,7 @@ readdirp@^2.0.0:
readable-stream "^2.0.2"
set-immediate-shim "^1.0.1"

recast@0.10.33:
recast@0.10.33, recast@^0.10.10:
version "0.10.33"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.10.33.tgz#942808f7aa016f1fa7142c461d7e5704aaa8d697"
dependencies:
Expand All @@ -2986,15 +2992,6 @@ recast@0.10.33:
private "~0.1.5"
source-map "~0.5.0"

recast@^0.10.10:
version "0.10.43"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.10.43.tgz#b95d50f6d60761a5f6252e15d80678168491ce7f"
dependencies:
ast-types "0.8.15"
esprima-fb "~15001.1001.0-dev-harmony-fb"
private "~0.1.5"
source-map "~0.5.0"

recast@^0.11.17:
version "0.11.18"
resolved "https://registry.yarnpkg.com/recast/-/recast-0.11.18.tgz#07af6257ca769868815209401d4d60eef1b5b947"
Expand Down Expand Up @@ -3146,7 +3143,7 @@ requires-port@1.0.x, requires-port@1.x.x:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"

resolve@1.1.x, resolve@^1.1.6:
resolve@1.1.7, resolve@1.1.x, resolve@^1.1.6:
version "1.1.7"
resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b"

Expand All @@ -3166,6 +3163,26 @@ ripemd160@0.2.0:
version "0.2.0"
resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-0.2.0.tgz#2bf198bde167cacfa51c0a928e84b68bbe171fce"

rollup-plugin-node-resolve@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-2.0.0.tgz#07e0ae94ac002a3ea36e8f33ca121d9f836b1309"
dependencies:
browser-resolve "^1.11.0"
builtin-modules "^1.1.0"
resolve "^1.1.6"

rollup-plugin-uglify@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/rollup-plugin-uglify/-/rollup-plugin-uglify-1.0.1.tgz#11d0b0c8bcd2d07e6908f74fd16b0152390b922a"
dependencies:
uglify-js "^2.6.1"

rollup@^0.37.0:
version "0.37.0"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.37.0.tgz#759a51708ac08b027597babff171a026cf712d8d"
dependencies:
source-map-support "^0.4.0"

"semver@2 || 3 || 4 || 5", semver@^5.0.1, semver@~5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.3.0.tgz#9b2ce5d3de02d17c6012ad326aa6b4d0cf54f94f"
Expand Down Expand Up @@ -3736,7 +3753,7 @@ typescript@^2.0.3, typescript@^2.1.4:
version "2.1.4"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-2.1.4.tgz#b53b69fb841126acb1dd4b397d21daba87572251"

uglify-js@^2.6, uglify-js@~2.7.3:
uglify-js@^2.6, uglify-js@^2.6.1, uglify-js@~2.7.3:
version "2.7.5"
resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.7.5.tgz#4612c0c7baaee2ba7c487de4904ae122079f2ca8"
dependencies:
Expand Down

0 comments on commit a4b5500

Please sign in to comment.