-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
build.mjs
66 lines (58 loc) · 1.3 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
60
61
62
63
64
65
66
import * as esbuild from 'esbuild';
import process from 'node:process';
const baseConfig = {
entryPoints: ['src/index.ts'],
bundle: true,
logLevel: 'info'
};
const umdConfig = {
...baseConfig,
format: 'iife',
// The following are hacks to basically make this an UMD module. No native support for that in esbuild as of today
globalName: 'Mp4Muxer',
footer: {
js:
`if (typeof module === "object" && typeof module.exports === "object") Object.assign(module.exports, Mp4Muxer)`
}
};
const esmConfig = {
...baseConfig,
format: 'esm'
};
let ctxUmd = await esbuild.context({
...umdConfig,
outfile: 'build/mp4-muxer.js'
});
let ctxEsm = await esbuild.context({
...esmConfig,
outfile: 'build/mp4-muxer.mjs'
});
let ctxUmdMinified = await esbuild.context({
...umdConfig,
outfile: 'build/mp4-muxer.min.js',
minify: true
});
let ctxEsmMinified = await esbuild.context({
...esmConfig,
outfile: 'build/mp4-muxer.min.mjs',
minify: true
});
if (process.argv[2] === '--watch') {
await Promise.all([
ctxUmd.watch(),
ctxEsm.watch(),
ctxUmdMinified.watch(),
ctxEsmMinified.watch(),
]);
} else {
ctxUmd.rebuild();
ctxEsm.rebuild();
ctxUmdMinified.rebuild();
ctxEsmMinified.rebuild();
await Promise.all([
ctxUmd.dispose(),
ctxEsm.dispose(),
ctxUmdMinified.dispose(),
ctxEsmMinified.dispose(),
]);
}