-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathesbuild.js
68 lines (63 loc) · 1.46 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
const esbuild = require("esbuild");
const copyStaticFiles = require("esbuild-copy-static-files");
// Get the environment
const isProduction = process.env.NODE_ENV === "production";
// Base configuration to compile the project
const baseConfig = {
entryPoints: {
index: "src/index.html",
bundle: "src/index.tsx",
},
bundle: true,
outdir: "public",
loader: { ".html": "copy" },
treeShaking: true,
plugins: [
{
name: "rebuild-notify",
setup(build) {
build.onEnd((_) => {
console.log(`Build completed.`);
});
},
},
copyStaticFiles({
src: "./src/static",
dest: "./public",
dereference: true,
errorOnExist: false,
preserveTimestamps: true,
recursive: true,
}),
],
};
// Configuration for development and production
const config = {
...baseConfig,
inject: isProduction ? [] : ["src/livereload.js"],
sourcemap: !isProduction,
minify: isProduction,
};
// Start the build
if (!isProduction) {
esbuild
.context(config)
.then((ctx) => {
// Start the watch mode
ctx.watch();
// Start the server
ctx
.serve({
servedir: "public",
port: 8000,
})
.then((server) => {
console.log(
`Server started on http://localhost:${server.host}:${server.port}`
);
});
})
.catch(() => process.exit(1));
} else {
esbuild.build(config).catch(() => process.exit(1));
}