-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy path.esbuild.js
More file actions
42 lines (35 loc) · 1.13 KB
/
Copy path.esbuild.js
File metadata and controls
42 lines (35 loc) · 1.13 KB
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
import { build } from 'esbuild'
const NODE_BUILTINS = ['fs', 'fs/promises', 'url', 'path']
// WASM codec packages — loaded on demand by audio-decode / encode-audio
const CODECS = [
'@audio/decode-*', '@audio/encode-*',
]
// Atoms an op loads on demand (`import('@audio/…')`) stay out of the bundle: fetched on first use.
// The device backends (speaker, mic) are I/O, not DSP: play()/record() need them in the page.
const lazyAtoms = {
name: 'lazy-atoms',
setup(build) {
build.onResolve({ filter: /^@audio\// }, args => args.kind === 'dynamic-import' && !/^@audio\/(speaker|mic)\b/.test(args.path) ? { path: args.path, external: true } : undefined)
}
}
const base = {
entryPoints: ['audio.js'],
bundle: true,
format: 'esm',
platform: 'browser',
plugins: [lazyAtoms],
}
// dist/audio.js — core + dispatch, codecs load on demand via import()
await build({
...base,
outfile: 'dist/audio.js',
external: [...NODE_BUILTINS, ...CODECS],
})
// dist/audio.min.js — same, minified
await build({
...base,
outfile: 'dist/audio.min.js',
external: [...NODE_BUILTINS, ...CODECS],
minify: true,
})
console.log('done')