Repository navigation
Expand file tree
/
Copy pathbuild.mjs
More file actions
63 lines (52 loc) · 1.39 KB
/
Copy pathbuild.mjs
File metadata and controls
63 lines (52 loc) · 1.39 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as esbuild from 'esbuild';
import { globSync } from 'glob';
console.log('Start build');
const entryPoints = globSync('src/**/*.{ts,tsx}');
const commonConfig = {
entryPoints,
outbase: 'src',
logLevel: 'info',
platform: 'browser',
target: 'es2020',
jsx: 'transform',
bundle: false, // We don't want one big file, we want a mirror of src
minify: true,
sourcemap: false,
packages: 'external',
};
async function build() {
const start = performance.now();
await Promise.all([
// Individual ESM files (mirror of src) - for deep imports & max compat
esbuild.build({
...commonConfig,
format: 'esm',
outdir: 'dist/esm',
// outExtension: { '.js': '.mjs' },
// plugins: [addMjsExtension],
}),
// Build CJS (Legacy/Node)
esbuild.build({
...commonConfig,
format: 'cjs',
outdir: 'dist/cjs',
// outExtension: { '.js': '.cjs' },
// plugins: [addCjsExtension],
}),
// Single ESM bundle - for modern bundlers with tree shaking
// esbuild.build({
// ...commonConfig,
// entryPoints: ['src/index.ts'],
// bundle: true,
// format: 'esm',
// outfile: 'dist/index.js',
// }),
]);
const stop = performance.now();
console.log(`Build complete - ${(stop - start) / 1000}s`);
}
build().catch((e) => {
console.log('Build error');
console.log(e);
process.exit(1)
});