-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathrollup.config.js
49 lines (45 loc) · 1.12 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
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import { babel } from '@rollup/plugin-babel';
import terser from '@rollup/plugin-terser';
// 基础配置
const baseConfig = (uglify = true) => {
const config = {
input: 'src/index.js',
plugins: [
resolve(),
commonjs(),
babel({ babelHelpers: 'runtime' }),
// terser(),
]
};
if (uglify) {
config.plugins.push(terser());
}
return config;
}
// 针对不同格式的具体配置
const umdConfig = {
...baseConfig(),
output: {
file: 'build/postmessage-promise.umd.js', // 输出文件
format: 'umd', // 构建为UMD格式
name: 'postMessagePromise', // 全局变量名
},
};
const esConfig = {
...baseConfig(false),
output: {
file: 'build/postmessage-promise.esm.js', // 输出文件
format: 'es', // 构建为esm格式
},
};
const cjsConfig = {
...baseConfig(false),
output: {
file: 'build/postmessage-promise.cjs.js', // 输出文件
format: 'cjs', // 构建为cjs格式
},
};
// 导出配置数组
export default [umdConfig, esConfig, cjsConfig];