perf(vite.config | view/sidebar): CI/CD 支持 | 构建信息显示

+ 适配Jenkins 持续集成功能。
    + 当版本库中出现新版本将自动构建并部署,以保证服务器版本为最新
+ 侧边栏下显示当前构建版本 和 构建时间
This commit is contained in:
2026-02-11 20:56:08 +08:00
parent 5eab7c7b82
commit e7a59de3ae
2 changed files with 57 additions and 2 deletions

View File

@@ -1,13 +1,27 @@
import path from 'path'
import { defineConfig, loadEnv } from 'vite'
import createVitePlugins from './vite/plugins'
import { execSync } from 'node:child_process'
const baseUrl = 'http://127.0.0.1:8080' // 后端接口
// https://vitejs.dev/config/
export default defineConfig(({ mode, command }) => {
const env = loadEnv(mode, process.cwd())
const { VITE_APP_ENV } = env
let commitId = 'unknown'
try {
commitId = execSync('git rev-parse --short HEAD')
.toString()
.trim()
} catch (e) {
console.log('git commit not found')
}
const buildTime = new Date().toISOString()
return {
// 部署生产环境和开发环境下的URL。
// 默认情况下vite 会假设你的应用是被部署在一个域名的根路径上
@@ -75,6 +89,10 @@ export default defineConfig(({ mode, command }) => {
}
]
}
}
},
define: {
__BUILD_TIME__: JSON.stringify(buildTime),
__COMMIT_ID__: JSON.stringify(commitId)
},
}
})