forked from onesy-me/onesy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
108 lines (93 loc) · 2.46 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
import path from 'path';
import resolve 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 wd = process.cwd();
const env = process.env.ENV;
const variant = process.env.VARIANT;
let ext = 'ts';
if (['react', 'vue'].indexOf(env) > -1) ext = 'tsx';
const inputRelative = `./src/index.${ext}`;
const input = path.resolve(wd, inputRelative);
const module = path.basename(wd);
const globals = {
react: 'React',
vue: 'Vue',
};
const extensions = ['.js', '.jsx', '.ts', '.tsx'];
const options = {
babel: {
exclude: /node_modules/,
babelHelpers: 'runtime',
extensions,
configFile: path.resolve(wd, '../../babel.config.js'),
},
resolve: {
preferBuiltins: false,
extensions,
},
commonjs: {
ignoreGlobal: true,
include: /node_modules/,
sourceMap: false
},
};
const plugins = [
resolve(options.resolve),
babel(options.babel),
commonjs(options.commonjs),
nodeGlobals({
buffer: false,
}),
json({ compact: true })
];
function onwarn(warning) {
if (['THIS_IS_UNDEFINED', 'MISSING_NODE_BUILTINS', 'CIRCULAR_DEPENDENCY'].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('');
const other = {};
if (variant === 'icons') other['sourcemap'] = false;
export default [
{
input,
onwarn,
output: {
file: `build/umd/${module}.dev.js`,
format: 'umd',
name,
globals,
...other
},
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,
...other
},
external: Object.keys(globals),
plugins: [
...plugins,
replace({ preventAssignment: true, 'process.env.NODE_ENV': JSON.stringify('production') }),
terser(),
sizeSnapshot({ snapshotPath: path.resolve(wd, 'size-snapshot.json') }),
],
},
];