-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
74 lines (63 loc) · 1.64 KB
/
esbuild.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import autoprefixer from "autoprefixer";
import * as esbuild from "esbuild";
import postCssPlugin from "esbuild-style-plugin";
import * as fs from "fs";
import * as path from "path";
import tailwindcss from "tailwindcss";
const ROOT_PATH = import.meta.dirname;
const OUT_PATH = path.join(ROOT_PATH, "unogame", "static", "dist");
// console.log(ROOT_PATH);
const isDev = process.env.NODE_ENV === "development";
if (fs.existsSync(OUT_PATH)) {
fs.rmSync(OUT_PATH, { recursive: true, force: true });
}
const CONFIG = {
bundle: true,
format: "esm",
outdir: OUT_PATH,
minify: !isDev,
sourcemap: isDev,
logLevel: "info",
};
const FE_CONFIG = {
...CONFIG,
entryPoints: [path.join(ROOT_PATH, "unogame", "frontendV2", "index.ts")],
};
const CSS_CONFIG = {
...CONFIG,
entryPoints: [
path.join(ROOT_PATH, "unogame", "frontendV2", "css", "style.css"),
],
plugins: [
postCssPlugin({
postcss: {
plugins: [tailwindcss, autoprefixer],
},
}),
],
};
const BE_CONFIG = {
...CONFIG,
entryPoints: [path.join(ROOT_PATH, "unogame", "backend", "server.ts")],
platform: "node",
packages: "external",
};
if (isDev) {
async function watch() {
let ctxBE = await esbuild.context(BE_CONFIG);
console.log("Building BE");
await ctxBE.watch();
let ctxCSS = await esbuild.context(CSS_CONFIG);
console.log("Building CSS");
await ctxCSS.watch();
let ctxFE = await esbuild.context(FE_CONFIG);
console.log("Building FE");
await ctxFE.watch();
console.log("Watching...");
}
watch();
} else {
await esbuild.build(BE_CONFIG);
await esbuild.build(CSS_CONFIG);
await esbuild.build(FE_CONFIG);
}