-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
52 lines (44 loc) · 1.19 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
import path from 'path'
import json from '@rollup/plugin-json'
import ts from 'rollup-plugin-typescript2' // ts插件
import node_resolve from '@rollup/plugin-node-resolve' //解析第三方模块
const packagesDir = path.resolve(__dirname, 'packages')
const packageDir = path.resolve(packagesDir, process.env.TARGET)
const resolve = (p) => {
return path.resolve(packageDir, p)
}
const pkg = require(resolve('package.json'))
const name = path.basename(packageDir)
const outputConfigs = {
'esm': {
file: resolve(`dist/${name}.esm-builder.js`),
format: 'es'
},
'cjs': {
file: resolve(`dist/${name}.cjs.js`),
format: 'cjs'
},
'global': {
file: resolve(`dist/${name}.global.js`),
format: 'iife' //立即执行函数 ,或者给 umd
}
}
function createConfig(format, output) {
output.name = options.name
output.sourcemap = true
return {
input: resolve('src/index.ts'),
output,
plugins: [
json(),
ts({
tsconfig: path.resolve(__dirname, 'tsconfig.json')
}),
node_resolve()
]
}
}
const options = pkg.buildOptions
export default options.formats.map(format => {
return createConfig(format, outputConfigs[format])
})