UNPKG

3.61 kBJavaScriptView Raw
1import nodeResolve from 'rollup-plugin-node-resolve';
2import { terser } from 'rollup-plugin-terser';
3import sourcemaps from 'rollup-plugin-sourcemaps';
4
5const MINIFY = process.env.MINIFY;
6const MONOLITHIC = process.env.MONOLITHIC;
7const ROUTER = process.env.ROUTER;
8const EVENTS = process.env.EVENTS;
9const RESOLVE = process.env.RESOLVE;
10
11const pkg = require('./package.json');
12let banner = `/**
13 * ${pkg.description}`;
14if (ROUTER && MONOLITHIC) {
15 banner += `
16 * NOTICE: This monolithic bundle also bundles the @uirouter/core code.
17 * This causes it to be incompatible with plugins that depend on @uirouter/core.
18 * We recommend switching to the ui-router-core.js and ui-router-angularjs.js bundles instead.
19 * For more information, see https://ui-router.github.io/blog/uirouter-for-angularjs-umd-bundles`;
20} else if (ROUTER) {
21 banner += `
22 * This bundle requires the ui-router-core.js bundle from the @uirouter/core package.`;
23}
24banner += `
25 * @version v${pkg.version}
26 * @link ${pkg.homepage}
27 * @license MIT License, http://www.opensource.org/licenses/MIT
28 */`;
29
30const terserOpts = { output: {} };
31// retain multiline comment with @license
32terserOpts.output.comments = (node, comment) => comment.type === 'comment2' && /@license/i.test(comment.value);
33
34const onwarn = (warning) => {
35 // Suppress this error message... https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined
36 const ignores = ['THIS_IS_UNDEFINED'];
37 if (!ignores.some((code) => code === warning.code)) {
38 console.error(warning.message);
39 }
40};
41
42const plugins = [nodeResolve({ jsnext: true }), sourcemaps()];
43
44if (MINIFY) plugins.push(terser(terserOpts));
45
46const extension = MINIFY ? '.min.js' : '.js';
47
48const BASE_CONFIG = {
49 onwarn: onwarn,
50 plugins: plugins,
51};
52
53const BASE_OUTPUT = {
54 banner: banner,
55 exports: 'named',
56 format: 'umd',
57 sourcemap: true,
58};
59
60const ROUTER_CONFIG = Object.assign(
61 {
62 input: 'lib-esm/index.js',
63 external: ['angular', '@uirouter/core'],
64 output: Object.assign(
65 {
66 file: 'release/ui-router-angularjs' + extension,
67 name: '@uirouter/angularjs',
68 globals: { angular: 'angular', '@uirouter/core': '@uirouter/core' },
69 },
70 BASE_OUTPUT
71 ),
72 },
73 BASE_CONFIG
74);
75
76// Also bundles the code from @uirouter/core into the same bundle
77const MONOLITHIC_ROUTER_CONFIG = Object.assign(
78 {
79 input: 'lib-esm/index.js',
80 external: 'angular',
81 output: Object.assign(
82 {
83 file: 'release/angular-ui-router' + extension,
84 name: '@uirouter/angularjs',
85 globals: { angular: 'angular' },
86 },
87 BASE_OUTPUT
88 ),
89 },
90 BASE_CONFIG
91);
92
93const EVENTS_CONFIG = Object.assign({}, BASE_CONFIG, {
94 input: 'lib-esm/legacy/stateEvents.js',
95 external: ['angular', '@uirouter/core'],
96 output: Object.assign(
97 {
98 file: 'release/stateEvents' + extension,
99 name: '@uirouter/angularjs-state-events',
100 globals: { angular: 'angular', '@uirouter/core': '@uirouter/core' },
101 },
102 BASE_OUTPUT
103 ),
104});
105
106const RESOLVE_CONFIG = Object.assign({}, BASE_CONFIG, {
107 input: 'lib-esm/legacy/resolveService.js',
108 external: ['angular', '@uirouter/core'],
109 output: Object.assign(
110 {
111 file: 'release/resolveService' + extension,
112 name: '@uirouter/angularjs-resolve-service',
113 globals: { angular: 'angular', '@uirouter/core': '@uirouter/core' },
114 },
115 BASE_OUTPUT
116 ),
117});
118
119const CONFIG = RESOLVE
120 ? RESOLVE_CONFIG
121 : EVENTS
122 ? EVENTS_CONFIG
123 : MONOLITHIC
124 ? MONOLITHIC_ROUTER_CONFIG
125 : ROUTER
126 ? ROUTER_CONFIG
127 : ROUTER_CONFIG;
128
129export default CONFIG;