-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
59 lines (52 loc) · 1.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
import path from 'path';
import resolve from 'rollup-plugin-node-resolve'; // 依赖引用插件
import commonjs from 'rollup-plugin-commonjs'; // commonjs模块转换插件
import { terser } from 'rollup-plugin-terser';
import ts from 'rollup-plugin-typescript2';
import packageJSON from './package.json';
const getPath = _path => path.resolve(__dirname, _path);
const name = packageJSON.name;
const extensions = [
'.js',
'.ts',
'.tsx'
];
const tsPlugin = ts({
tsconfig: getPath('./tsconfig.json'), // 导入本地ts配置
extensions
});
const outputConfigs = [{
file: getPath(`dist/${name}.esm.js`),
format: `es`
}, {
file: getPath(`dist/${name}.cjs.js`),
format: `cjs`
}, {
file: getPath(`dist/${name}.umd.js`),
format: `umd`
}];
const commonConfig = {
input: getPath('./src/index.ts'),
plugins: [
resolve(),
commonjs(),
terser({
compress: {
ecma: 2015,
pure_getters: true
},
safari10: true,
format: {
comments: false,
},
}),
tsPlugin
]
};
const buildConf = options => Object.assign({}, commonConfig, options);
export default outputConfigs.map(output => buildConf({
output: {
name: packageJSON.name,
...output
}
}));