-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserve.js
33 lines (32 loc) · 1005 Bytes
/
serve.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
const { build } = require("esbuild")
const chokidar = require("chokidar")
const liveServer = require("live-server")
;(async () => {
const builder = await build({
bundle: true,
define: { "process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || "development") },
entryPoints: ["src/index.jsx"],
incremental: true,
minify: process.env.NODE_ENV === "production",
outfile: "public/bundle.js",
})
// `chokidar` watcher source changes.
chokidar
// Watches TypeScript and React TypeScript.
.watch("src/**/*.{js,jsx}", {
interval: 0, // No delay
})
// Rebuilds esbuild (incrementally -- see `build.incremental`).
.on("all", () => {
builder.rebuild()
})
// `liveServer` local server for hot reload.
liveServer.start({
// Opens the local server on start.
open: true,
// Uses `PORT=...` or 8080 as a fallback.
port: +process.env.PORT || 8080,
// Uses `public` as the local server folder.
root: "public",
})
})()