-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuild.mjs
59 lines (56 loc) · 1.86 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
57
58
59
import * as process from 'node:process';
import * as child_process from 'node:child_process';
import * as esbuild from 'esbuild';
import metaUrlPlugin from '@chialab/esbuild-plugin-meta-url';
const gitCommit = child_process.execSync('git rev-parse HEAD', { encoding: 'utf-8' }).replace(/\n$/, '');
const mode = (process.argv[2] ?? 'build');
const options = {
logLevel: 'info',
plugins: [metaUrlPlugin()],
bundle: true,
loader: {
'.html': 'copy',
'.svg': 'dataurl',
'.ttf': 'file',
'.woff': 'file',
'.woff2': 'file',
'.json': 'file',
'.wasm': 'file',
'.asm.wasm': 'copy',
'.zip': 'file',
},
external: [
'fs/promises', // @yowasp/yosys
'node-fetch', // pyodide
],
define: {
'globalThis.GIT_COMMIT': `"${mode === 'minify' ? gitCommit : 'HEAD'}"`,
'globalThis.IS_PRODUCTION': (mode === 'minify' ? 'true' : 'false'),
},
target: 'es2021',
format: 'esm',
sourcemap: 'linked',
minify: (mode === 'minify'),
outdir: 'dist',
entryPoints: {
'index': './src/index.html',
'app': './src/app.tsx',
'app.worker': './src/worker.ts',
'editor.worker': 'monaco-editor/esm/vs/editor/editor.worker.js',
'pyodide.asm': 'pyodide/pyodide.asm.wasm',
},
};
if (mode === 'build' || mode === 'minify') {
await esbuild.build(options);
} else if (mode === 'watch') {
const context = await esbuild.context(options);
await context.watch();
} else if (mode === 'serve') {
const context = await esbuild.context(options);
await context.rebuild();
await context.watch();
// Specifying `servedir` is necessary for files built by meta URL plugin to be accessible.
await context.serve({ servedir: 'dist', port: 8010 });
} else {
console.error(`Usage: ${process.argv0} [build|watch|serve|minify]`);
}