-
Notifications
You must be signed in to change notification settings - Fork 0
/
rollup.config.js
57 lines (51 loc) · 1.58 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
// 通过 rollup进行打包
//(1)引入相关依赖
import ts from 'rollup-plugin-typescript2' //解析 ts
import json from '@rollup/plugin-json'
import resolvePlugin from '@rollup/plugin-node-resolve' //解析 第三方 插件
import path from 'path' // 处理路径
//(2)获取文件路径
let packagesDir = path.resolve(__dirname,'packages') //
// 2.1 获取需要打包的包
const packageDir = path.resolve(packagesDir, process.env.TARGET)
//2.2 打包获取到 每个包的项目配置
const resolve = p => path.resolve(packageDir, p)
const pkg = require(resolve(`package.json`)) //获取 json
const name = path.basename(packageDir)
console.log(name,6666) //注意
//3创建一个 表
const outputOpions ={
"esm-bundler":{
file:resolve(`dist/${name}.esm-bundler.js`) ,
format:'es'
},
"cjs":{
file:resolve(`dist/${name}.cjs.js`) ,
format:'cjs'
},
"global":{
file:resolve(`dist/${name}.global.js`) ,
format:'iife'
}
}
const options = pkg.buildOptions
function createConfig(format,output){
//进行打包
console.log()
output.name = options.name
output.sourcemap = true
//生成rollup配置
return {
input:resolve('src/index.ts'), //导入
output,
plugins:[
json(),
ts({ //解析 ts
tsconfig:path.resolve(__dirname,'tsconfig.json')
}),
resolvePlugin() //解析 第三方 插件
]
}
}
//rullup 需要 导出一个配置
export default options.formats.map(format=>createConfig(format,outputOpions[format]))