feat: 初始化文字马赛克生成器
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/`)
|
||||
@@ -0,0 +1,11 @@
|
||||
import homepage from '../index.html'
|
||||
|
||||
const server = Bun.serve({
|
||||
port: Number(Bun.env.PORT ?? 5173),
|
||||
routes: {
|
||||
'/': homepage,
|
||||
},
|
||||
development: true,
|
||||
})
|
||||
|
||||
console.log(`文字马赛克开发服务器:http://localhost:${server.port}`)
|
||||
Reference in New Issue
Block a user