-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
55 lines (49 loc) · 1.51 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
import ts from 'rollup-plugin-typescript2'; // 解析ts
import json from '@rollup/plugin-json'; // 解析
import resolvePlugin from '@rollup/plugin-node-resolve'; // 解析第三方
import path from 'path'; // 处理路径
// 获取文件路径
let packagesDirs = path.resolve(__dirname, 'packages');
// 获取需要打包的包
let packageDir = path.resolve(packagesDirs, process.env.TARGET);
const resolve = (p) => path.resolve(packageDir, p); // 只想自身包路径
const pkg = require(resolve(`package.json`)); // 获取每个包的json
const packageOptions = pkg.buildOptions || {}; // 获取配置
const name = path.basename(packageDir);
console.log('需要的包配置=>>', packageOptions);
// 创建一个映射表
const outputOptions = {
'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 createOptions(format, output) {
// 进行打包
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() // 解析第三方包
]
};
}
export default options.formats.map((format) => createOptions(format, outputOptions[format]));