Skip to content

Commit af5f0c6

Browse files
committed
Add ESM bundle
1 parent f58c975 commit af5f0c6

8 files changed

+1152
-35
lines changed

.eslintrc.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = {
1616
'plugins': [
1717
'@typescript-eslint'
1818
],
19-
'ignorePatterns': ['build/*.js', 'build.mjs'],
19+
'ignorePatterns': ['build/*.js', 'build/*.mjs', 'build.mjs'],
2020
'rules': {
2121
'prefer-const': ['off'],
2222
'@typescript-eslint/no-explicit-any': ['off'],

build.mjs

+26-14
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,46 @@
11
import * as esbuild from 'esbuild';
22

3-
const config = {
3+
const baseConfig = {
44
entryPoints: ['src/index.ts'],
55
bundle: true,
6+
logLevel: 'info'
7+
};
8+
9+
const umdConfig = {
10+
...baseConfig,
611
format: 'iife',
7-
logLevel: 'info',
812

913
// The following are hacks to basically make this an UMD module. No native support for that in esbuild as of today
1014
globalName: 'Mp4Muxer',
1115

12-
// Object.assign(module.exports, Mp4Muxer) would make us lose named exports in CJS-to-ESM interop
1316
footer: {
1417
js:
15-
`if (typeof module === "object" && typeof module.exports === "object") {
16-
module.exports.Muxer = Mp4Muxer.Muxer;
17-
module.exports.ArrayBufferTarget = Mp4Muxer.ArrayBufferTarget;
18-
module.exports.StreamTarget = Mp4Muxer.StreamTarget;
19-
module.exports.FileSystemWritableFileStreamTarget = Mp4Muxer.FileSystemWritableFileStreamTarget;
20-
}`
18+
`if (typeof module === "object" && typeof module.exports === "object") Object.assign(module.exports, Mp4Muxer)`
2119
}
2220
};
2321

24-
let ctx = await esbuild.context({
25-
...config,
22+
const esmConfig = {
23+
...baseConfig,
24+
format: 'esm'
25+
};
26+
27+
let ctxUmd = await esbuild.context({
28+
...umdConfig,
2629
outfile: 'build/mp4-muxer.js'
2730
});
28-
let ctxMinified = await esbuild.context({
29-
...config,
31+
let ctxEsm = await esbuild.context({
32+
...esmConfig,
33+
outfile: 'build/mp4-muxer.mjs'
34+
});
35+
let ctxUmdMinified = await esbuild.context({
36+
...umdConfig,
3037
outfile: 'build/mp4-muxer.min.js',
3138
minify: true
3239
});
40+
let ctxEsmMinified = await esbuild.context({
41+
...esmConfig,
42+
outfile: 'build/mp4-muxer.min.mjs',
43+
minify: true
44+
});
3345

34-
await Promise.all([ctx.watch(), ctxMinified.watch()]);
46+
await Promise.all([ctxUmd.watch(), ctxEsm.watch(), ctxUmdMinified.watch(), ctxEsmMinified.watch()]);

build/mp4-muxer.d.ts

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/mp4-muxer.js

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/mp4-muxer.min.js

+1-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)