-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.mjs
56 lines (53 loc) · 1.34 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
49
50
51
52
53
54
55
56
/* eslint-env node */
import * as esbuild from 'esbuild';
import { copy } from 'esbuild-plugin-copy';
import { replace } from 'esbuild-plugin-replace';
const env = process.env;
const options = {
entryPoints: ['src/index.tsx', 'src/index.html'],
bundle: true,
outdir: 'dist',
minify: process.env.NODE_ENV === 'production',
sourcemap: process.env.NODE_ENV !== 'production',
target: 'es2018',
logLevel: 'info',
loader: {
'.html': 'copy',
'.woff': 'file',
'.woff2': 'file',
'.3mf': 'copy',
},
plugins: [
copy({
// this is equal to process.cwd(), which means we use cwd path as base path to resolve `to` path
// if not specified, this plugin uses ESBuild.build outdir/outfile options as base path.
resolveFrom: 'cwd',
assets: {
from: [
'./public/**/*.3mf',
'./public/*.png',
'./public/*.ico',
'./public/*.webmanifest',
],
to: ['./dist'],
},
watch: true,
}),
replace({
__TRACKER_SNIPPET: env.TRACKER_SNIPPET || '',
}),
],
};
if (process.argv?.length > 2) {
const ctx = await esbuild.context(options);
if (process.argv.includes('--watch')) {
await ctx.watch();
}
if (process.argv.includes('--serve')) {
await ctx.serve({
servedir: 'dist',
});
}
} else {
await esbuild.build(options);
}