-
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
import { type BunPlugin, plugin } from "bun";
import { Plugin } from "esbuild";
// A plugin compatible for both Bun and ESBuild
export const cssPlugin = {
name: "CSS loader",
async setup(build) {
const { bundle } = await import("lightningcss");
build.onLoad(
{
filter: /\/?website\/.+\.css$/,
},
({ path }) => {
if (path.endsWith(".module.css")) {
const { code, exports } = bundle({
filename: path,
minify: true,
cssModules: true,
sourceMap: false,
});
const simplied = Object.fromEntries(
Object.entries(exports || {}).map(([key, value]) => [
key,
value.name,
]),
);
// Bun's bundler seems not to support "object" loader.
return {
loader: "js",
contents:
"export default " +
JSON.stringify(code.toString()) +
";export const cx=" +
JSON.stringify(simplied) +
";",
};
}
const { code } = bundle({
filename: path,
minify: true,
sourceMap: false,
});
// Bun runtime seems not to support "text" loader.
return {
loader: "js",
contents: "export default " + JSON.stringify(code.toString()),
};
},
);
},
} satisfies BunPlugin & Plugin;
await plugin(cssPlugin);