fix(web): 构建后补回 assets/.gitkeep,保证新克隆可直接 go build
This commit is contained in:
1 parent
7d5d94f815
commit
b62bb022bd
2 files changed
+17
-3
No files matched your search
Whitespace-only changes.
+17
-3
@@ -1,17 +1,31 @@
|
|||||||
import { fileURLToPath, URL } from 'node:url'
|
import { fileURLToPath, URL } from 'node:url'
|
||||||
import { defineConfig } from 'vite'
|
import { writeFileSync } from 'node:fs'
|
||||||
|
import { join } from 'node:path'
|
||||||
|
import { defineConfig, type Plugin } from 'vite'
|
||||||
import vue from '@vitejs/plugin-vue'
|
import vue from '@vitejs/plugin-vue'
|
||||||
|
|
||||||
const resolve = (p: string) => fileURLToPath(new URL(p, import.meta.url))
|
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({
|
export default defineConfig({
|
||||||
plugins: [vue()],
|
plugins: [vue(), keepAssetsGitkeep()],
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: { '@': resolve('./src') },
|
alias: { '@': resolve('./src') },
|
||||||
},
|
},
|
||||||
build: {
|
build: {
|
||||||
// 构建产物直接输出到 Go 的 embed 目录
|
// 构建产物直接输出到 Go 的 embed 目录
|
||||||
outDir: resolve('../server/internal/webui/assets'),
|
outDir,
|
||||||
emptyOutDir: true,
|
emptyOutDir: true,
|
||||||
rollupOptions: {
|
rollupOptions: {
|
||||||
input: {
|
input: {
|
||||||
|
|||||||
Reference in new issue
Block a user