-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.mjs
65 lines (57 loc) · 1.58 KB
/
esbuild.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
import * as esbuild from "esbuild";
import { clean } from "esbuild-plugin-clean";
import { sassPlugin } from "esbuild-sass-plugin";
import manifestPlugin from "esbuild-plugin-manifest";
import fs from "fs";
const config = {
entryPoints: [
{ in: "assets/js/app.js", out: "js/app" },
{ in: "assets/css/app.scss", out: "css/app" },
"assets/ugent/images/**/*",
"assets/ugent/favicon.ico",
"assets/ugent/fonts/**/*",
],
outdir: "static/",
bundle: true,
minify: true,
sourcemap: true,
legalComments: "linked",
loader: {
".ico": "copy",
".woff": "copy",
".woff2": "copy",
".svg": "copy",
".png": "copy",
},
plugins: [
clean({ patterns: ["./static/*"] }),
sassPlugin({
embedded: true,
}),
manifestPlugin({
filter: (fn) => !fn.endsWith(".map") && !fn.endsWith(".LEGAL.txt"),
generate: generateManifest,
}),
],
};
if (process.argv.includes("--watch")) {
const ctx = await esbuild.context(config);
await ctx.watch();
console.log("ESBuild running. Watching for changes...");
} else {
console.log(
"---------------------------------- Building assets ----------------------------------",
);
const result = await esbuild.build(config);
fs.writeFileSync("meta.json", JSON.stringify(result.metafile));
console.log(
"-------------------------------------------------------------------------------------",
);
}
function generateManifest(input) {
return Object.entries(input).reduce((out, [k, v]) => {
// Remove "static" from keys
out[k.replace("static", "")] = `/${v}`;
return out;
}, {});
}