-
-
Notifications
You must be signed in to change notification settings - Fork 22
/
esbuild-image-templates.js
45 lines (42 loc) · 1.08 KB
/
esbuild-image-templates.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
import { readdir } from "node:fs/promises";
import * as esbuild from "esbuild";
import { sassPlugin } from "esbuild-sass-plugin";
const outdir = process.argv[2];
if (!outdir) {
console.error("Missing output directory argument");
process.exit(1);
}
const result = await esbuild.build({
entryPoints: (await readdir("jg/coop/image_templates"))
.filter((file) => file.endsWith(".scss"))
.map((file) => `jg/coop/image_templates/${file}`),
bundle: true,
minify: true,
sourcemap: true,
metafile: true,
target: "es2020",
loader: {
".svg": "copy",
".jpg": "copy",
".png": "copy",
".webp": "copy",
".woff": "copy",
".woff2": "copy",
},
assetNames: "assets/[name]",
plugins: [
sassPlugin({
precompile(source, pathname) {
if (pathname.endsWith("@fontsource/inter/index.css")) {
return source.replaceAll(
"./files/",
"../../../node_modules/@fontsource/inter/files/",
);
}
return source;
},
}),
],
outdir,
});
console.log(JSON.stringify(result.metafile, null, 2));