-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
61 lines (51 loc) · 1.4 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
// 获取打包文件
import path from "node:path";
import typescript from "@rollup/plugin-typescript";
import json from "@rollup/plugin-json";
import resolvePlugin from "@rollup/plugin-node-resolve";
const packagesDir = path.resolve("packages");
// 获取需要打包的路径
const packageDir = path.resolve(packagesDir, process.env.TARGET);
const resolve = (p) => path.resolve(packageDir, p);
const pkg = require(resolve(`package.json`));
const packageOptions = pkg.buildOptions || {};
const name = packageOptions.name || path.basename(packageDir);
const outputConfigs = {
"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 pkgBuildOptions = packageOptions.formats || [];
console.log(path.resolve("tsconfig.json"));
function createConfig(buildType, output) {
return {
input: resolve("src/index.ts"),
output: {
...output,
name,
sourcemap: true,
},
plugins: [
json(),
typescript({
tsconfig: path.resolve("tsconfig.json"),
}),
resolvePlugin(),
],
};
}
console.log(
pkgBuildOptions.map((format) => createConfig(format, outputConfigs[format]))
);
export default pkgBuildOptions.map((format) =>
createConfig(format, outputConfigs[format])
);