39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
import { fileURLToPath, URL } from 'node:url'
|
|
import { writeFileSync } from 'node:fs'
|
|
import { join } from 'node:path'
|
|
import { defineConfig, type Plugin } from 'vite'
|
|
import vue from '@vitejs/plugin-vue'
|
|
|
|
const resolve = (p: string) => fileURLToPath(new URL(p, import.meta.url))
|
|
const outDir = resolve('../server/internal/webui/assets')
|
|
|
|
// emptyOutDir 会把 .gitkeep 一起删掉,导致「新克隆的仓库没构建前端时 go:embed 匹配不到文件」。
|
|
// 构建结束后补回来,保证任何状态下 go build 都能通过。
|
|
function keepAssetsGitkeep(): Plugin {
|
|
return {
|
|
name: 'scoreboard:keep-assets-gitkeep',
|
|
closeBundle() {
|
|
writeFileSync(join(outDir, '.gitkeep'), '')
|
|
},
|
|
}
|
|
}
|
|
|
|
export default defineConfig({
|
|
plugins: [vue(), keepAssetsGitkeep()],
|
|
resolve: {
|
|
alias: { '@': resolve('./src') },
|
|
},
|
|
build: {
|
|
// 构建产物直接输出到 Go 的 embed 目录
|
|
outDir,
|
|
emptyOutDir: true,
|
|
rollupOptions: {
|
|
input: {
|
|
index: resolve('./index.html'),
|
|
display: resolve('./display.html'),
|
|
admin: resolve('./admin.html'),
|
|
},
|
|
},
|
|
},
|
|
})
|