-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
46 lines (40 loc) · 967 Bytes
/
Copy pathserver.js
File metadata and controls
46 lines (40 loc) · 967 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
34
35
36
37
38
39
40
41
42
43
44
45
46
const chokidar = require("chokidar");
const liveServer = require("live-server");
const params = {
port: 3000,
host: "0.0.0.0",
root: "dist",
open: false,
file: "index.html",
wait: 100,
logLevel: 2,
middleware: [
function (req, res, next) {
next();
},
],
};
const BUILD = require.resolve("./build");
async function rebuild() {
try {
console.log("Rebuilding...");
delete require.cache[BUILD];
const { buildCSS, buildDocs } = require(BUILD);
await buildCSS();
await buildDocs();
console.log("Done.");
} catch (e) {
console.error("Build failed:", e.message);
}
}
const watcher = chokidar.watch(["gui", "docs", "build.js"], {
persistent: true,
ignoreInitial: true,
});
watcher.on("change", () => rebuild());
watcher.on("add", () => rebuild());
watcher.on("unlink", () => rebuild());
rebuild().then(() => {
liveServer.start(params);
console.log("Server running at http://localhost:3000");
});