-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrollup.config.js
127 lines (121 loc) · 3.28 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
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import { nodeResolve } from "@rollup/plugin-node-resolve";
import esbuild from "rollup-plugin-esbuild";
import { minify } from "rollup-plugin-esbuild";
import { emptyDir } from "rollup-plugin-empty-dir";
import del from "rollup-plugin-delete";
import cleanup from "rollup-plugin-cleanup";
import dts from "rollup-plugin-dts";
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 allIcons = globSync(["src/icons/*", "src/icons/*/*.js"], {
ignore: {
ignored: (p) => /index\.js$/.test(p.name),
},
});
// 统一格式化路径
return allIcons.map((file) => {
// 如果是文件,使用 path.parse 取文件名;如果是目录,用相对路径
return file.endsWith(".js")
? `./${path.parse(file).name}`
: `./${path.relative("src", file)}`;
});
}
// 获取多入口文件输入
function getFileInput() {
const files = globSync([
// "icons-*.js",
"src/index.js",
"src/map.js",
"src/runtime/*.js",
"src/icons/*/*.js",
]);
return Object.fromEntries(
files.map((file) => {
// 判断是否是根目录的文件
const isRootFile = path.isAbsolute(file) || !file.startsWith("src/");
const relativePath = isRootFile
? path.basename(file, path.extname(file)) // 根目录文件使用文件名作为键
: path.relative(
// 相对于 `src` 文件夹生成相对路径
"src",
file.slice(0, file.length - path.extname(file).length)
);
return [
relativePath,
// 使用 `fileURLToPath` 将文件路径转换为 URL 文件路径
fileURLToPath(new URL(file, import.meta.url)),
];
})
);
}
// 默认参数
const baseOutputConfig = {
// compact: true,
entryFileNames: "[name].js",
chunkFileNames: "[name].js",
globals: {
vue: "Vue",
},
manualChunks: {
gsap: ["gsap"],
},
};
const config = [
{
input: getFileInput(),
external: ["vue", "./map", "../../runtime", ...getIconExternals()],
plugins: [
del({ targets: "packages/*" }),
nodeResolve(),
// esbuild({
// minifySyntax: true,
// minifyWhitespace: false,
// minifyIdentifiers: false,
// }),
// minify({
// minify: false, // 关闭默认的压缩
// minifySyntax: false, // 只启用语法压缩
// minifyWhitespace: false,
// minifyIdentifiers: false,
// }),
cleanup(),
],
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",
},
],
},
];
// console.log(JSON.stringify(config, null, 2));
export default config;