给环境变量加个VITE_前缀

This commit is contained in:
洛洛希雅 2024-04-26 22:33:09 +08:00
parent b3d011a1f0
commit dc7e3d6820
3 changed files with 7 additions and 57 deletions

View File

@ -60,12 +60,12 @@ import { ElMessage } from 'element-plus'
import moment from 'moment' import moment from 'moment'
const buildEnv = (() => { const buildEnv = (() => {
let time = import.meta.env.TAG_TIMESTAMP let time = import.meta.env.VITE_TAG_TIMESTAMP
if (!time) return null if (!time) return null
const date = new Date(Number.parseInt(time)) const date = new Date(Number.parseInt(time))
time = `${moment(date).format('YYYY-mm-dd HH:mm:ss')} GMT+8` time = `${moment(date).format('YYYY-mm-dd HH:mm:ss')} GMT+8`
const build = import.meta.env.BUILD_DISPLAY_NAME const build = import.meta.env.VITE_BUILD_DISPLAY_NAME
const hash = (import.meta.env.GIT_COMMIT || '').slice(0, 8) const hash = (import.meta.env.VITE_GIT_COMMIT || '').slice(0, 8)
return `构建 ${build} ${hash} ${time}` return `构建 ${build} ${hash} ${time}`
})() })()

53
typings/env.d.ts vendored
View File

@ -4,56 +4,9 @@ declare global {
readonly VITE_APP_BASE_URL: string readonly VITE_APP_BASE_URL: string
readonly VITE_APP_BASE_PORT: number readonly VITE_APP_BASE_PORT: number
readonly VITE_APP_ENV: 'prod' | 'test' | 'dev' readonly VITE_APP_ENV: 'prod' | 'test' | 'dev'
readonly VITE_TAG_TIMESTAMP: string
// Jenkins 的环境变量 readonly VITE_BUILD_DISPLAY_NAME: string
// readonly BRANCH_NAME: string readonly VITE_GIT_COMMIT: string
// readonly BRANCH_IS_PRIMARY: string
// readonly CHANGE_ID: string
// readonly CHANGE_URL: string
// readonly CHANGE_TITLE: string
// readonly CHANGE_AUTHOR: string//
// readonly CHANGE_AUTHOR_DISPLAY_NAME: string
// readonly CHANGE_AUTHOR_EMAIL: string
// readonly CHANGE_TARGET: string
// readonly CHANGE_BRANCH: string
// readonly CHANGE_FORK: string
// readonly TAG_NAME: string
readonly TAG_TIMESTAMP: string
// readonly TAG_UNIXTIME: string
// readonly TAG_DATE: string
// readonly JOB_DISPLAY_URL: string
// readonly RUN_DISPLAY_URL: string
// readonly RUN_ARTIFACTS_DISPLAY_URL: string
// readonly RUN_CHANGES_DISPLAY_URL: string
// readonly RUN_TESTS_DISPLAY_URL: string
// readonly CI: string;
// readonly BUILD_NUMBER: string
// readonly BUILD_ID: string
readonly BUILD_DISPLAY_NAME: string
// readonly JOB_NAME: string
// readonly JOB_BASE_NAME: string
// readonly BUILD_TAG: string
// readonly EXECUTOR_NUMBER: string
// readonly NODE_NAME: string
// readonly NODE_LABELS: string
// readonly WORKSPACE: string
// readonly WORKSPACE_TMP: string
// readonly JENKINS_HOME: string
// readonly JENKINS_URL: string
// readonly BUILD_URL: string
// readonly JOB_URL: string
readonly GIT_COMMIT: string
// readonly GIT_PREVIOUS_COMMIT: string
// readonly GIT_PREVIOUS_SUCCESSFUL_COMMIT: string
// readonly GIT_BRANCH: string
// readonly GIT_LOCAL_BRANCH: string
// readonly GIT_CHECKOUT_DIR: string
// readonly GIT_URL: string
// readonly GIT_COMMITTER_NAME: string
// readonly GIT_AUTHOR_NAME: string
// readonly GIT_COMMITTER_EMAIL: string
// readonly GIT_AUTHOR_EMAIL: string
// 更多环境变量... // 更多环境变量...
} }
interface ImportMeta { interface ImportMeta {

View File

@ -23,10 +23,7 @@ export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
define: { define: {
//define global var //define global var
GLOBAL_STRING: JSON.stringify('i am global var from vite.config.js define'), GLOBAL_STRING: JSON.stringify('i am global var from vite.config.js define'),
GLOBAL_VAR: { test: 'i am global var from vite.config.js define' }, GLOBAL_VAR: { test: 'i am global var from vite.config.js define' }
'import.meta.env.TAG_TIMESTAMP': JSON.stringify(process.env.TAG_TIMESTAMP),
'import.meta.env.BUILD_DISPLAY_NAME': JSON.stringify(process.env.BUILD_DISPLAY_NAME),
'import.meta.env.GIT_COMMIT': JSON.stringify(process.env.GIT_COMMIT)
}, },
clearScreen: false, //设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息 clearScreen: false, //设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息
server: { server: {