-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathesbuild.config.js
More file actions
33 lines (30 loc) · 975 Bytes
/
esbuild.config.js
File metadata and controls
33 lines (30 loc) · 975 Bytes
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
import * as esbuild from "esbuild";
const isProduction = process.env.NODE_ENV === "production";
const isWatch = process.argv.includes("--watch");
const assetVersion = new Date().toISOString().slice(0, 10).replace(/-/g, '');
const config = {
entryPoints: ["src/main.js"],
bundle: true,
minify: isProduction,
sourcemap: !isProduction,
target: ["es2020", "chrome90", "firefox88", "safari14", "edge90"],
outfile: "dist/main.js",
format: "esm",
platform: "browser",
logLevel: "info",
define: {
"process.env.NODE_ENV": JSON.stringify(
isProduction ? "production" : "development",
),
"import.meta.env.BASE_PATH": JSON.stringify(process.env.BASE_PATH || ""),
"import.meta.env.ASSET_VERSION": JSON.stringify(assetVersion),
},
};
if (isWatch) {
const ctx = await esbuild.context(config);
await ctx.watch();
console.log("👀 Watching for changes...");
} else {
await esbuild.build(config);
console.log("✅ Build complete!");
}