-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
97 lines (73 loc) · 2.34 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
import path from 'path';
import typescript from 'rollup-plugin-typescript2';
import { terser } from 'rollup-plugin-terser';
import dts from "rollup-plugin-dts";
//rollup默认采用es module引用方式,该插件可支持编译使用commonjs的库
import commonjs from '@rollup/plugin-commonjs';
//rollup默认无法去处理import _ from 'lodash'这类的模块引入,因此需要此插件解析,从而打包进文件
import nodeResolve from '@rollup/plugin-node-resolve';
// import babel, { getBabelOutputPlugin } from '@rollup/plugin-babel';
import json from '@rollup/plugin-json';
import pkg from './package.json';
const libName = pkg.name;
const libVersion = pkg.version;
const libDir = path.resolve(__dirname, 'src');
const resolve = p => path.resolve(libDir, p);
const configs = {
'esm': {
file: `dist/${libName}.esm.js`,
format: 'esm',// cjs iife umd amd es system
name: libName,
exports: 'named',
inlineDynamicImports: true,
},
'cjs': {
file: `dist/${libName}.cjs.js`,
format: 'cjs',
name: libName,
//options:default(只能export default)、named(支持export和export default共存)、none(不需要export、export default时)
exports: 'named',
},
'umd': {
file: `dist/${libName}.min.js`,
format: 'umd',
name: libName,
exports: 'named',
plugins: [
terser({
compress: {
drop_console: true,
drop_debugger: true
},
format: {
comments: false
}
}),
],
extend: true
},
}
const createBundleconf = (type) => ({
input: resolve('index.ts'),
output: configs[type],
plugins: [
nodeResolve({
extensions: ['.ts', '.js']
}),// 查找和打包node_modules中的第三方模块
commonjs(), //将 CommonJS 转换成 ES2015 模块供 Rollup 处理
json(),
typescript({
// useTsconfigDeclarationDir: true
})
],
external: [
],
});
const typesConf = {
input: resolve('index.ts'),
output: [{
file: "dist/index.d.ts", format: "es"
}],
plugins: [dts()],
};
export default [...Object.keys(configs).map(createBundleconf), typesConf];