-
Notifications
You must be signed in to change notification settings - Fork 423
/
build.mjs
41 lines (38 loc) · 942 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
39
40
41
import esbuild from 'esbuild';
import fs from 'fs/promises';
import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill';
function buildWorker({ entry, out, debug, external } = {}) {
return esbuild.build({
plugins: [NodeModulesPolyfillPlugin()],
platform: 'browser',
conditions: ['worker', 'browser'],
entryPoints: [entry],
sourcemap: true,
outfile: out,
external,
logLevel: 'warning',
format: 'esm',
target: 'es2022',
bundle: true,
minify: !debug,
define: {
IS_CLOUDFLARE_WORKER: 'true',
},
loader: {
'.html': 'text',
'.css': 'text',
'.txt': 'text',
},
metafile: true,
legalComments: 'external',
});
}
let result = await buildWorker({
entry: './src/worker.js',
out: './dist/worker.js',
debug: false,
});
if (result.metafile) {
// use https://esbuild.github.io/analyze/ to analyses
await fs.writeFile('./dist/metafile.json', JSON.stringify(result.metafile));
}