28 lines
704 B
TypeScript
28 lines
704 B
TypeScript
import { rm } from 'node:fs/promises'
|
|
import { resolve, sep } from 'node:path'
|
|
|
|
const projectRoot = resolve(import.meta.dir, '..')
|
|
const outputDirectory = resolve(projectRoot, 'dist')
|
|
|
|
if (!outputDirectory.startsWith(`${projectRoot}${sep}`)) {
|
|
throw new Error(`拒绝清理项目之外的输出目录:${outputDirectory}`)
|
|
}
|
|
|
|
await rm(outputDirectory, { recursive: true, force: true })
|
|
|
|
const result = await Bun.build({
|
|
entrypoints: [resolve(projectRoot, 'index.html')],
|
|
outdir: outputDirectory,
|
|
target: 'browser',
|
|
})
|
|
|
|
if (!result.success) {
|
|
for (const log of result.logs) {
|
|
console.error(log)
|
|
}
|
|
|
|
process.exit(1)
|
|
}
|
|
|
|
console.log(`已生成 ${result.outputs.length} 个文件到 dist/`)
|