2025-01-21 16:29:37 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
|
|
import process from 'node:process'
|
|
|
|
|
|
|
|
|
|
import esbuild from 'esbuild'
|
|
|
|
|
|
|
|
|
|
import { sharedEsbuildConfig } from './esbuild.config.js'
|
2025-10-19 21:31:36 +00:00
|
|
|
import { instrumentWithSourceMaps } from './utils/instrument.js'
|
2025-01-21 16:29:37 +00:00
|
|
|
|
|
|
|
|
const config = sharedEsbuildConfig
|
|
|
|
|
|
|
|
|
|
const prod = process.argv[2] === 'production'
|
2025-10-19 21:31:36 +00:00
|
|
|
const coverage = process.argv[2] === 'coverage'
|
2025-01-21 16:29:37 +00:00
|
|
|
|
|
|
|
|
const context = await esbuild.context({
|
|
|
|
|
...config,
|
|
|
|
|
...prod
|
|
|
|
|
? { minify: true, sourcemap: false }
|
|
|
|
|
: {},
|
2025-10-19 21:31:36 +00:00
|
|
|
...coverage
|
|
|
|
|
? { minify: false, sourcemap: 'inline' }
|
|
|
|
|
: {},
|
2025-01-21 16:29:37 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (prod) {
|
|
|
|
|
await context.rebuild()
|
|
|
|
|
process.exit(0)
|
2025-10-19 21:31:36 +00:00
|
|
|
} else if (coverage) {
|
|
|
|
|
await context.rebuild()
|
|
|
|
|
instrumentWithSourceMaps('out/main.js', 'out/main.js')
|
|
|
|
|
process.exit(0)
|
2025-01-21 16:29:37 +00:00
|
|
|
} else {
|
|
|
|
|
await context.watch()
|
|
|
|
|
}
|