-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
53 lines (43 loc) · 1.14 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
const path = require('path');
const { terser } = require('rollup-plugin-terser');
const pkg = require('./package.json');
const deps = [...Object.keys(pkg.peerDependencies || {}), ...Object.keys(pkg.dependencies || {})];
const external = id => deps.includes(id) || /@babel\/runtime\//.test(id);
const inputPath = path.join(__dirname, 'src', 'index.js');
const getBasicConf = () => ({
input: inputPath,
external,
});
const getDistLib = moduleType => {
switch (moduleType) {
case 'cjs':
return 'dist';
case 'es':
return 'es';
default:
throw Error('Unknown Module Type');
}
};
const getConf = (env, moduleType) => {
const distLib = getDistLib(moduleType);
const fileName = `${pkg.name}.${env}.js`;
const outputPath = path.join(distLib, fileName);
const isProduction = env === 'production';
const plugins = [];
if (isProduction) {
plugins.push(terser());
}
return {
...getBasicConf(),
output: {
file: outputPath,
format: moduleType,
},
plugins,
};
};
module.exports = [
getConf('development', 'cjs'),
getConf('production', 'cjs'),
getConf('development', 'es'),
];