-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.mjs
93 lines (87 loc) · 2.02 KB
/
rollup.config.mjs
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
90
91
92
93
import { nodeResolve } from "@rollup/plugin-node-resolve";
import del from 'rollup-plugin-delete'
import dts from "rollup-plugin-dts";
import { terser } from "rollup-plugin-terser";
import path from "path";
import { fileURLToPath } from "url";
import { globSync } from "glob";
// 获取当前模块文件的 URL (ES模块)
const __filename = fileURLToPath(import.meta.url);
// 获取当前模块目录的路径
const __dirname = path.dirname(__filename);
// 获取/icons文件夹下的所有图标名称
function getIconExternals() {
const iconFiles = globSync(path.resolve(__dirname, "src/icons/*.js"));
return iconFiles.map(
(file) => `./icons/${path.basename(file, path.extname(file))}`
);
}
// 获取多入口文件输入
function getFileInput() {
const files = globSync([
"src/index.js",
"src/map.js",
"src/runtime/*.js",
"src/icons/*.js",
]);
return Object.fromEntries(
files.map((file) => [
path.relative(
// 相对于 `src` 文件夹生成相对路径
"src",
file.slice(0, file.length - path.extname(file).length)
),
file,
])
);
}
// 默认参数
const baseOutputConfig = {
// compact: true,
// entryFileNames: '[name].js',
chunkFileNames: "[name].js",
globals: {
vue: "Vue",
},
// manualChunks: {
// gsap: ["gsap"],
// },
};
export default [
{
input: getFileInput(),
external: ["vue", "./map", "../runtime", ...getIconExternals()],
plugins: [
del({ targets: 'packages/*' }),
nodeResolve(),
terser(),
],
output: [
{
format: "es",
dir: "packages/es",
...baseOutputConfig,
},
{
format: "cjs",
dir: "packages/cjs",
...baseOutputConfig,
},
],
},
{
input: getFileInput(),
external: ["vue", "./map", "../runtime", ...getIconExternals()],
plugins: [dts()],
output: [
{
dir: "packages/es",
format: "es",
},
{
dir: "packages/cjs",
format: "cjs",
},
],
},
];