-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.js
More file actions
41 lines (37 loc) · 911 Bytes
/
Copy pathbuild.js
File metadata and controls
41 lines (37 loc) · 911 Bytes
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
import { build } from 'esbuild'
import { spawnSync } from 'child_process'
// Type-check and emit declarations first; abort on type errors
const tsc = spawnSync(
process.execPath,
['node_modules/typescript/bin/tsc', '-p', 'tsconfig.build.json'],
{ stdio: 'inherit' },
)
if (tsc.status !== 0) process.exit(tsc.status ?? 1)
const shared = {
bundle: true,
platform: 'node',
target: 'node18',
external: [],
}
await Promise.all([
build({
...shared,
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
format: 'esm',
}),
build({
...shared,
entryPoints: ['src/index.ts'],
outfile: 'dist/index.cjs',
format: 'cjs',
}),
build({
...shared,
entryPoints: ['src/cli.ts'],
outfile: 'dist/cli.js',
format: 'esm',
banner: { js: '#!/usr/bin/env node' },
}),
])
console.log('Built dist/index.js, dist/index.cjs, dist/cli.js, dist/index.d.ts')