-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.ts
More file actions
55 lines (46 loc) · 1.3 KB
/
build.ts
File metadata and controls
55 lines (46 loc) · 1.3 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
import * as esbuild from 'esbuild'
import fs from 'node:fs'
import { builtinModules } from 'node:module'
import path from 'node:path'
import pkg from './package.json'
const isProd = process.argv.includes('--prod')
async function runBuild() {
try {
const outdir = path.join(import.meta.dirname, './dist')
if (fs.existsSync(outdir)) fs.rmSync(outdir, { recursive: true, force: true })
const commonOptions: esbuild.BuildOptions = {
entryPoints: ['src/index.ts'],
bundle: true,
minify: isProd,
sourcemap: true,
platform: 'node',
// format: 'esm',
target: 'node22',
// outdir,
external: [
...builtinModules,
...builtinModules.map((m) => `node:${m}`),
...Object.keys(pkg.dependencies || {}),
...Object.keys(pkg.devDependencies || {}),
],
define: {
'process.env.NODE_ENV': isProd ? '"production"' : '"development"',
},
logLevel: 'info',
}
await esbuild.build({
...commonOptions,
format: 'cjs',
outfile: path.join(outdir, 'index.js'),
})
await esbuild.build({
...commonOptions,
format: 'esm',
outfile: path.join(outdir, 'index.mjs'),
})
} catch (error) {
console.error('❌ Build failed:', error)
process.exit(1)
}
}
runBuild()