-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrolldown.config.ts
More file actions
66 lines (60 loc) · 1.48 KB
/
Copy pathrolldown.config.ts
File metadata and controls
66 lines (60 loc) · 1.48 KB
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
import { defineConfig, RolldownPluginOption } from "rolldown";
import fs from "node:fs";
import path from "node:path";
const rolldownCopyCssPlugin: RolldownPluginOption = {
name: "rolldown-plugin-copy-css",
buildStart() {
const srcDir = path.resolve("public/scss");
// 如果目录不存在则直接跳过
if (!fs.existsSync(srcDir)) return;
const files = fs.readdirSync(srcDir);
for (const file of files) {
if (file.endsWith(".scss")) {
const filePath = path.join(srcDir, file);
const source = fs.readFileSync(filePath, "utf-8");
// 将 CSS 注册为 Asset 资源
// 这里的 fileName 是相对于 Rolldown 配置中 output.dir(例如 'build')的路径
this.emitFile({
type: "asset",
fileName: `css/${file}`,
source: source
});
}
}
}
};
export default defineConfig([
{
input: ["lib/index.ts"],
platform: "node",
output: {
dir: "build",
format: "es",
cleanDir: true,
strict: true,
topLevelVar: true,
minify: {
compress: true,
mangle: false
},
sourcemap: true
}
},
{
input: ["public/client.ts"],
platform: "browser",
output: {
dir: "build/public",
format: "umd",
cleanDir: true,
strict: true,
topLevelVar: true,
minify: {
compress: true,
mangle: false
},
sourcemap: true
},
plugins: [rolldownCopyCssPlugin]
}
]);