This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { execFileSync } from 'node:child_process'
|
||||
import { defineConfig, loadEnv } from 'vite'
|
||||
import uni from '@dcloudio/vite-plugin-uni'
|
||||
|
||||
@@ -6,8 +7,28 @@ const normalizeEnvUrl = (value: string | undefined, fallback: string) => {
|
||||
return normalized || fallback
|
||||
}
|
||||
|
||||
const resolveGitCommit = () => {
|
||||
try {
|
||||
return execFileSync('git', ['rev-parse', '--short=12', 'HEAD'], {
|
||||
encoding: 'utf8'
|
||||
}).trim()
|
||||
} catch {
|
||||
return 'unknown'
|
||||
}
|
||||
}
|
||||
|
||||
const createBuildTimestamp = () => (
|
||||
new Date().toISOString().replace(/[-:.TZ]/g, '').slice(0, 14)
|
||||
)
|
||||
|
||||
export default defineConfig(({ mode }) => {
|
||||
const env = loadEnv(mode, process.cwd(), '')
|
||||
const gitCommit = normalizeEnvUrl(env.VITE_APP_GIT_COMMIT, resolveGitCommit())
|
||||
const buildId = normalizeEnvUrl(
|
||||
env.VITE_APP_BUILD_ID,
|
||||
`${gitCommit}-${createBuildTimestamp()}`
|
||||
)
|
||||
const buildPlatform = process.env.UNI_PLATFORM === 'mp-weixin' ? 'mp-weixin' : 'h5'
|
||||
const appApiProxyTarget = normalizeEnvUrl(env.DEV_PROXY_APP_API_TARGET, 'http://localhost:3001')
|
||||
const h5SdkProxyTarget = normalizeEnvUrl(env.DEV_PROXY_H5_SDK_TARGET, appApiProxyTarget)
|
||||
const sdkProxyTarget = normalizeEnvUrl(env.DEV_PROXY_SDK_TARGET, appApiProxyTarget)
|
||||
@@ -18,6 +39,11 @@ export default defineConfig(({ mode }) => {
|
||||
return {
|
||||
base: normalizeEnvUrl(env.VITE_APP_PUBLIC_BASE, '/'),
|
||||
plugins: [uni()],
|
||||
define: {
|
||||
__APP_BUILD_ID__: JSON.stringify(buildId),
|
||||
__APP_GIT_COMMIT__: JSON.stringify(gitCommit),
|
||||
__APP_BUILD_PLATFORM__: JSON.stringify(buildPlatform)
|
||||
},
|
||||
server: {
|
||||
host: '0.0.0.0',
|
||||
proxy: {
|
||||
|
||||
Reference in New Issue
Block a user