forked from Ragudos/todo-app-frontend-mentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esbuild.config.mjs
45 lines (40 loc) · 1.21 KB
/
esbuild.config.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
import esbuild from "esbuild";
import fs from "node:fs";
import path from "node:path";
import url from "url";
import pugPlugin from "./esbuild.plugin.mjs";
import { is } from "drizzle-orm";
const __dirname = url.fileURLToPath(new URL(".", import.meta.url));
const args = process.argv;
const isWatch = args[2]?.trim() == "--watchmode";
const mode = isWatch ? "context" : "build";
try {
const ctx = await esbuild[mode]({
bundle: true,
metafile: true,
format: "cjs",
minify: isWatch ? false : true,
platform: "node",
entryPoints: [
path.resolve(__dirname, "./src/index.ts"),
path.resolve(__dirname, "./src/views/**/*.pug")
],
outdir: path.resolve(__dirname, isWatch ? "./dev-build" : "./build"),
assetNames: "[dir]/[name]-[hash]",
outExtension: {
".js": ".cjs"
},
packages: isWatch ? "external" : undefined,
plugins: [
pugPlugin(),
]
});
if (isWatch) {
ctx.watch();
} else {
fs.writeFileSync(path.resolve(__dirname, "./build/server.meta.json"), JSON.stringify(ctx.metafile));
}
} catch (err) {
console.error(err);
process.exit(1);
}