-
Notifications
You must be signed in to change notification settings - Fork 37
/
rollup.config.js
87 lines (75 loc) · 2.13 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
import { nodeResolve } from '@rollup/plugin-node-resolve';
import { terser } from 'rollup-plugin-terser';
import sourcemaps from 'rollup-plugin-sourcemaps';
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 plugins = [nodeResolve(), sourcemaps(), commonjs()];
if (MINIFY) {
plugins.push(
terser({
format: {
// retain multiline comment with @license
comments: (node, comment) => {
return comment.type == 'comment2' && /@license/i.test(comment.value);
},
},
})
);
}
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) {
let externals = [
'@uirouter/core',
'@uirouter/angularjs',
'@uirouter/react',
'react',
'react-dom',
'prop-types',
'angular',
];
let regexps = externals
.map((e) => [
new RegExp(`^${e}$`),
// new RegExp(`commonjs-proxy.${e}$`),
new RegExp(`node_modules/${e}`),
])
.reduce((acc, a) => acc.concat(a), []);
return regexps.map((regex) => regex.exec(id)).reduce((acc, val) => acc || !!val, false);
}
const CONFIG = {
input: 'lib-esm/index.js',
output: {
name: '@uirouter/react-hybrid',
file: '_bundles/ui-router-react-hybrid' + extension,
sourcemap: true,
format: 'umd',
banner: banner,
exports: 'named',
globals: {
'@uirouter/angularjs': '@uirouter/angularjs',
'@uirouter/react': '@uirouter/react',
'@uirouter/core': '@uirouter/core',
angular: 'angular',
react: 'React',
'react-dom': 'ReactDOM',
'prop-types': 'PropTypes',
},
},
plugins: plugins,
onwarn: onwarn,
external: isExternal,
};
export default CONFIG;