-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
95 lines (84 loc) · 2.21 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
import path from 'path';
import nodeResolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import babel from '@rollup/plugin-babel';
import replace from '@rollup/plugin-replace';
import nodeGlobals from 'rollup-plugin-node-globals';
import { terser } from 'rollup-plugin-terser';
import { sizeSnapshot } from 'rollup-plugin-size-snapshot';
import json from '@rollup/plugin-json';
const inputRelative = './src/index.ts';
const input = path.resolve(process.cwd(), inputRelative);
const module = path.basename(process.cwd());
const globals = {
'http': 'http',
'https': 'https',
'events': 'events'
};
const extensions = ['.ts', '.js'];
const options = {
babel: {
exclude: /node_modules/,
babelHelpers: 'runtime',
extensions,
configFile: path.resolve('babel.config.js'),
},
nodeResolve: {
preferBuiltins: false,
extensions,
},
commonjs: {
ignoreGlobal: true,
include: /node_modules/,
},
};
const plugins = [
nodeResolve(options.nodeResolve),
babel(options.babel),
commonjs(options.commonjs),
nodeGlobals({
buffer: false,
}),
json({ compact: true })
];
function onwarn(warning) {
if (['THIS_IS_UNDEFINED', 'MISSING_NODE_BUILTINS'].indexOf(warning.code) > -1) return;
console.warn(warning);
throw Error(warning.message);
}
const capitalize = value => `${value[0].toUpperCase()}${value.slice(1).toLowerCase()}`;
const name = module.split('-').map(item => capitalize(item)).join('');
export default [
{
input,
onwarn,
output: {
file: `build/umd/${module}.dev.js`,
format: 'umd',
name,
globals,
},
external: Object.keys(globals),
plugins: [
...plugins,
replace({ preventAssignment: true, 'process.env.NODE_ENV': JSON.stringify('development') }),
],
},
{
input,
onwarn,
output: {
file: `build/umd/${module}.prod.min.js`,
format: 'umd',
name,
globals,
},
external: Object.keys(globals),
plugins: [
...plugins,
replace({ preventAssignment: true, 'process.env.NODE_ENV': JSON.stringify('production') }),
terser(),
sizeSnapshot({ snapshotPath: path.resolve(process.cwd(), 'size-snapshot.json') }),
],
},
];