-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
55 lines (49 loc) · 1.77 KB
/
Copy pathbuild.js
File metadata and controls
55 lines (49 loc) · 1.77 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
const esbuild = require("esbuild");
const { sassPlugin } = require("esbuild-sass-plugin");
const watch = process.argv.includes("--watch");
/** @type {import("esbuild").BuildOptions} */
const sharedOptions = {
bundle: true,
minify: !watch,
sourcemap: watch ? "inline" : false,
logLevel: "info",
};
async function build() {
// ── JavaScript ────────────────────────────────────────────────────────────
const jsCtx = await esbuild.context({
...sharedOptions,
entryPoints: ["assets/js/index.js"],
outfile: "public/assets/app.js",
});
// ── CSS / SCSS ─────────────────────────────────────────────────────────────
// The sass plugin resolves bare ~bootstrap/... imports via node_modules.
const cssCtx = await esbuild.context({
...sharedOptions,
entryPoints: ["assets/css/index.scss"],
outfile: "public/assets/app.css",
plugins: [
sassPlugin({
// Allow @import "bootstrap/scss/..." to resolve from node_modules
loadPaths: ["node_modules"],
// Suppress deprecation warnings that originate inside dependencies
// (Bootstrap 5 still uses the legacy Sass @import API)
quietDeps: true,
}),
],
});
if (watch) {
await jsCtx.watch();
await cssCtx.watch();
console.log("[esbuild] watching for changes…");
} else {
await jsCtx.rebuild();
await cssCtx.rebuild();
await jsCtx.dispose();
await cssCtx.dispose();
console.log("[esbuild] build complete");
}
}
build().catch((err) => {
console.error(err);
process.exit(1);
});