forked from ui-router/angular-hybrid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
79 lines (66 loc) · 2.1 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
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(),
visualizer({ sourcemap: true }),
];
if (MINIFY) plugins.push(uglify(uglifyOpts));
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/* , @angular/* , and angular (angularjs) should be external
let externals = [
/^@uirouter\/.*/,
/^@angular\/.*/,
/^angular$/,
];
return externals.map(regex => regex.exec(id)).reduce((acc, val) => acc || !!val, false);
}
const CONFIG = {
moduleName: '@uirouter/angular-hybrid',
entry: 'lib/index.js',
dest: '_bundles/ui-router-angular-hybrid' + extension,
sourceMap: true,
format: 'umd',
exports: 'named',
plugins: plugins,
banner: banner,
onwarn: onwarn,
external: isExternal,
globals: {
'@uirouter/angular': '@uirouter/angular',
'@uirouter/angularjs': '@uirouter/angularjs',
'@uirouter/core': '@uirouter/core',
'@uirouter/rx': '@uirouter/rx',
'@angular/core': 'ng.core',
'@angular/common': 'ng.common',
'@angular/upgrade/static': 'ng.upgrade.static',
'angular': 'angular',
}
};
export default CONFIG;