-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbuild.ts
More file actions
54 lines (46 loc) Β· 1.5 KB
/
Copy pathbuild.ts
File metadata and controls
54 lines (46 loc) Β· 1.5 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
import { rmSync } from 'node:fs';
import { execSync } from 'node:child_process';
// Clean dist directory
console.log('π§Ή Cleaning dist directory...');
rmSync('dist', { recursive: true, force: true });
// ESM build β keep peer deps external
console.log('π¦ Building ESM...');
const esmResult = await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target: 'node',
format: 'esm',
splitting: false,
sourcemap: 'none',
minify: false
// external: ESM_EXTERNAL_DEPS
});
if (!esmResult.success) {
console.error('β ESM build failed');
esmResult.logs.forEach((log) => console.error(log));
process.exit(1);
}
// CJS build β bundle all deps (including ESM-only ones like chalk) for CommonJS compatibility.
// This avoids "ERR_PACKAGE_PATH_NOT_EXPORTED" when bundlers like webpack/rspack call require().
console.log('π¦ Building CJS...');
const cjsResult = await Bun.build({
entrypoints: ['./src/index.ts'],
outdir: './dist',
target: 'node',
format: 'cjs',
naming: '[name].cjs',
splitting: false,
sourcemap: 'none',
minify: false
// No externals: bundle everything so require() works out of the box
});
if (!cjsResult.success) {
console.error('β CJS build failed');
cjsResult.logs.forEach((log) => console.error(log));
process.exit(1);
}
console.log('β
JavaScript build complete');
// Generate type definitions
console.log('π Generating type definitions...');
execSync('tsc -p tsconfig.build.json', { stdio: 'inherit' });
console.log('β
Build complete!');