-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
89 lines (80 loc) · 1.73 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
import resolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import ts from 'rollup-plugin-typescript2'
import path from 'path'
import packageJSON from './package.json'
const getPath = (_path) => path.resolve(__dirname, _path)
const extensions = ['.js', '.ts', '.tsx']
// // ts
const tsPlugin = ts({
tsconfig: getPath('./tsconfig.esm.json'), // 导入本地ts配置
extensions,
})
const resolvePlugin = resolve(extensions)
const commonjsPlugin = commonjs()
const commonConf = {
input: getPath('./src/index.ts'),
plugins: [tsPlugin, resolvePlugin],
output: {
name: packageJSON.name,
},
}
const preOutName = 'utils'
const output = (type, preName = preOutName) =>
path.resolve(__dirname, 'lib', `${preName}.${type}.js`)
const OutputFormat = {
// 异步模块定义,用于像RequireJS这样的模块加载器
AMD: 'amd',
//CommonJS,适用于 Node 和 Browserify/Webpack
CJS: 'cjs',
ESM: 'esm',
IIFE: 'iife',
UMD: 'umd',
SYSTEM: 'system',
}
function genOutPut(type) {
return {
output: {
format: type,
file: output(type),
},
}
}
const builds = [
{
output: {
file: packageJSON.main,
format: OutputFormat.CJS,
},
},
{
output: {
file: packageJSON.module,
format: OutputFormat.ESM,
},
},
{
output: {
name: packageJSON.name,
file: packageJSON.unpkg,
format: OutputFormat.UMD,
},
},
{
output: {
file: packageJSON.jsdelivr,
format: OutputFormat.IIFE,
},
},
genOutPut(OutputFormat.AMD),
genOutPut(OutputFormat.SYSTEM),
]
const buildConf = (options) => {
return {
...commonConf,
...options,
}
}
export default builds.map((output) => {
return buildConf(output)
})