-
Notifications
You must be signed in to change notification settings - Fork 0
/
builder.js
49 lines (45 loc) · 1.02 KB
/
builder.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
const { start } = require("live-server")
const { watch } = require("chokidar")
const { build } = require("esbuild")
const fs = require("fs-extra")
const { sassPlugin } = require("esbuild-sass-plugin")
// const { ScssModulesPlugin } = require("esbuild-scss-modules-plugin")
const isProd = process.env.NODE_ENV === "production"
const serverOptions = {
port: 8080,
root: "./dist",
open: true,
}
const buildOptions = {
entryPoints: ["App.tsx"],
loader: { ".ts": "tsx" },
bundle: true,
outdir: "dist",
format: "cjs",
minify: isProd,
sourcemap: true,
incremental: true,
plugins: [sassPlugin()],
}
;(async () => {
fs.remove("dist")
fs.copy("public", "dist")
let builder
try {
builder = await build(buildOptions)
} catch (e) {
console.warn(e.message)
}
if (!isProd) {
watch("src/**/*", { ignoreInitial: true }).on("all", () => {
try {
builder.rebuild()
} catch (e) {
console.warn(e.message)
}
})
start(serverOptions)
} else {
process.exit(0)
}
})()