forked from ui-router/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
106 lines (89 loc) · 3.17 KB
/
rollup.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import nodeResolve from 'rollup-plugin-node-resolve';
import uglify from 'rollup-plugin-uglify';
import progress from 'rollup-plugin-progress';
import sourcemaps from 'rollup-plugin-sourcemaps';
import visualizer from 'rollup-plugin-visualizer';
import commonjs from 'rollup-plugin-commonjs';
let MINIFY = process.env.MINIFY;
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
*/`;
let uglifyOpts = { output: {} };
// retain multiline comment with @license
uglifyOpts.output.comments = (node, comment) =>
comment.type === 'comment2' && /@license/i.test(comment.value);
let plugins = [
nodeResolve({ jsnext: true }),
progress(),
sourcemaps(),
commonjs(),
];
if (MINIFY) plugins.push(uglify(uglifyOpts));
if (MINIFY) plugins.push(visualizer({ sourcemap: true }));
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
function onwarn(warning) {
if (warning.code === 'THIS_IS_UNDEFINED') return;
console.error(warning.message);
}
function isExternal(id) {
// @uirouter/core and ui-router-rx should be external
// All rxjs and @angular/* should be external
// except for @angular/router/src/router_config_loader
let externals = [
/^ui-router-rx/,
/^@uirouter\/core/,
/^rxjs/,
/^@angular\/(?!router\/src\/router_config_loader)/,
];
return externals.map(regex => regex.exec(id)).reduce((acc, val) => acc || !!val, false);
}
const CONFIG = {
moduleName: '@uirouter/angular',
entry: 'lib/index.js',
dest: '_bundles/ui-router-ng2' + extension,
sourceMap: true,
format: 'umd',
exports: 'named',
plugins: plugins,
banner: banner,
onwarn: onwarn,
external: isExternal,
globals: {
'tslib': 'tslib',
'rxjs/ReplaySubject': 'Rx',
// Copied these from @angular/router rollup config
'rxjs/BehaviorSubject': 'Rx',
'rxjs/Observable': 'Rx',
'rxjs/Subject': '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',
'@uirouter/core': '@uirouter/core',
'ui-router-rx': 'ui-router-rx',
'@angular/core': 'ng.core',
'@angular/common': 'ng.common',
}
};
export default CONFIG;