-
Notifications
You must be signed in to change notification settings - Fork 17
/
build.mjs
48 lines (38 loc) · 1.14 KB
/
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
39
40
41
42
43
44
45
46
47
48
import * as esbuild from 'esbuild';
import * as vuePlugin from 'esbuild-plugin-vue3';
import * as fs from 'fs/promises';
import * as path from 'path';
const isDev = process.argv.includes('--dev');
// Minify and copy api.json
const interfaces = JSON.parse(await fs.readFile(path.resolve('api.json')));
await fs.writeFile(path.resolve('public', 'api.json'), JSON.stringify(interfaces));
// Esbuild
const esbuildOptions = {
entryPoints: ['src/documentation.ts', 'src/style.css'],
minify: true,
bundle: true,
sourcemap: true,
outdir: 'public/',
plugins: [vuePlugin.default()],
define: {
"process.env.NODE_ENV": JSON.stringify("production"),
},
};
if (isDev) {
esbuildOptions.banner = {
js: `window.DEV_MODE = true;new EventSource("/esbuild").addEventListener("change", () => location.reload());`
};
}
const context = await esbuild.context(esbuildOptions);
if (isDev) {
await context.watch();
const { host, port } = await context.serve({
host: 'localhost',
servedir: 'public/',
});
console.log(`Serving at http://${host}:${port}`);
} else {
console.log('Building');
await context.rebuild();
await context.dispose();
}