recreate project
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
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/`)
|
||||
Reference in New Issue
Block a user