forked from angular-ui/ui-router
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
129 lines (114 loc) · 3.52 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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import nodeResolve from 'rollup-plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import sourcemaps from 'rollup-plugin-sourcemaps';
const MINIFY = process.env.MINIFY;
const MONOLITHIC = process.env.MONOLITHIC;
const ROUTER = process.env.ROUTER;
const EVENTS = process.env.EVENTS;
const RESOLVE = process.env.RESOLVE;
const pkg = require('./package.json');
let banner = `/**
* ${pkg.description}`;
if (ROUTER && MONOLITHIC) {
banner += `
* NOTICE: This monolithic bundle also bundles the @uirouter/core code.
* This causes it to be incompatible with plugins that depend on @uirouter/core.
* We recommend switching to the ui-router-core.js and ui-router-angularjs.js bundles instead.
* For more information, see https://ui-router.github.io/blog/uirouter-for-angularjs-umd-bundles`;
} else if (ROUTER) {
banner += `
* This bundle requires the ui-router-core.js bundle from the @uirouter/core package.`;
}
banner += `
* @version v${pkg.version}
* @link ${pkg.homepage}
* @license MIT License, http://www.opensource.org/licenses/MIT
*/`;
const terserOpts = { output: {} };
// retain multiline comment with @license
terserOpts.output.comments = (node, comment) => comment.type === 'comment2' && /@license/i.test(comment.value);
const onwarn = (warning) => {
// Suppress this error message... https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
const ignores = ['THIS_IS_UNDEFINED'];
if (!ignores.some((code) => code === warning.code)) {
console.error(warning.message);
}
};
const plugins = [nodeResolve({ jsnext: true }), sourcemaps()];
if (MINIFY) plugins.push(terser(terserOpts));
const extension = MINIFY ? '.min.js' : '.js';
const BASE_CONFIG = {
onwarn: onwarn,
plugins: plugins,
};
const BASE_OUTPUT = {
banner: banner,
exports: 'named',
format: 'umd',
sourcemap: true,
};
const ROUTER_CONFIG = Object.assign(
{
input: 'lib-esm/index.js',
external: ['angular', '@uirouter/core'],
output: Object.assign(
{
file: 'release/ui-router-angularjs' + extension,
name: '@uirouter/angularjs',
globals: { angular: 'angular', '@uirouter/core': '@uirouter/core' },
},
BASE_OUTPUT
),
},
BASE_CONFIG
);
// Also bundles the code from @uirouter/core into the same bundle
const MONOLITHIC_ROUTER_CONFIG = Object.assign(
{
input: 'lib-esm/index.js',
external: 'angular',
output: Object.assign(
{
file: 'release/angular-ui-router' + extension,
name: '@uirouter/angularjs',
globals: { angular: 'angular' },
},
BASE_OUTPUT
),
},
BASE_CONFIG
);
const EVENTS_CONFIG = Object.assign({}, BASE_CONFIG, {
input: 'lib-esm/legacy/stateEvents.js',
external: ['angular', '@uirouter/core'],
output: Object.assign(
{
file: 'release/stateEvents' + extension,
name: '@uirouter/angularjs-state-events',
globals: { angular: 'angular', '@uirouter/core': '@uirouter/core' },
},
BASE_OUTPUT
),
});
const RESOLVE_CONFIG = Object.assign({}, BASE_CONFIG, {
input: 'lib-esm/legacy/resolveService.js',
external: ['angular', '@uirouter/core'],
output: Object.assign(
{
file: 'release/resolveService' + extension,
name: '@uirouter/angularjs-resolve-service',
globals: { angular: 'angular', '@uirouter/core': '@uirouter/core' },
},
BASE_OUTPUT
),
});
const CONFIG = RESOLVE
? RESOLVE_CONFIG
: EVENTS
? EVENTS_CONFIG
: MONOLITHIC
? MONOLITHIC_ROUTER_CONFIG
: ROUTER
? ROUTER_CONFIG
: ROUTER_CONFIG;
export default CONFIG;