-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.mjs
38 lines (33 loc) · 884 Bytes
/
build.mjs
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
import esbuild from "esbuild";
import vuePlugin from "esbuild-vue";
import workboxBuild from "workbox-build";
const rootDir = "public";
const config = {
entryPoints: ["src/main.js"],
bundle: true,
outfile: `${rootDir}/bundle.js`,
plugins: [vuePlugin()],
define: {
"process.env.NODE_ENV": JSON.stringify(process.env.BUILD || "development"),
},
};
if (!!process.env.LIVE) {
esbuild.serve({ servedir: rootDir }, config).then((server) => {
console.log(`Serving at http://localhost:${server.port}`);
});
} else {
esbuild.build(config);
}
// Build ServiceWorker
const modifyURLPrefix = {
[rootDir]: "",
};
if (process.env.SUBDIRECTORY) {
modifyURLPrefix[`/${process.env.SUBDIRECTORY}`] = "";
}
workboxBuild.generateSW({
swDest: `${rootDir}/sw.js`,
globDirectory: rootDir,
globPatterns: ["**/*.{js,html,css,webmanifest,png}"],
modifyURLPrefix,
});