移除暴露的过多环境变量

This commit is contained in:
洛洛希雅 2024-04-26 22:14:07 +08:00
parent 183a174bb1
commit b3300e3939
3 changed files with 41 additions and 40 deletions

View File

@ -65,7 +65,7 @@ const buildEnv = (() => {
const date = new Date(Number.parseInt(time))
time = `${moment(date).format('YYYY-mm-dd HH:mm:ss')} GMT+8`
const build = import.meta.env.BUILD_DISPLAY_NAME
const hash = import.meta.env.GIT_COMMIT
const hash = (import.meta.env.GIT_COMMIT || '').slice(0, 8)
return `构建 ${build} ${hash} ${time}`
})()

72
typings/env.d.ts vendored
View File

@ -6,33 +6,33 @@ declare global {
readonly VITE_APP_ENV: 'prod' | 'test' | 'dev'
// Jenkins 的环境变量
readonly BRANCH_NAME: 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 BRANCH_NAME: 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 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_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 JOB_NAME: string
// readonly JOB_BASE_NAME: string
// readonly BUILD_TAG: string
// readonly EXECUTOR_NUMBER: string
// readonly NODE_NAME: string
// readonly NODE_LABELS: string
@ -40,19 +40,19 @@ declare global {
// readonly WORKSPACE_TMP: string
// readonly JENKINS_HOME: string
// readonly JENKINS_URL: string
readonly BUILD_URL: string
readonly JOB_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
// 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
// 更多环境变量...
}

View File

@ -23,10 +23,11 @@ export default defineConfig(({ command, mode }: ConfigEnv): UserConfig => {
define: {
//define global var
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': process.env.TAG_TIMESTAMP,
'import.meta.env.BUILD_DISPLAY_NAME': process.env.BUILD_DISPLAY_NAME,
'import.meta.env.GIT_COMMIT': process.env.GIT_COMMIT
},
// Vite 和 Jenkins 的环境变量
envPrefix: ['VITE_', 'TAG_', 'BUILD_', 'BRANCH_', 'CHANGE_', 'JOB_', 'RUN_', 'GIT_'],
clearScreen: false, //设为 false 可以避免 Vite 清屏而错过在终端中打印某些关键信息
server: {
//hmr: { overlay: false }, //设置 server.hmr.overlay 为 false 可以禁用开发服务器错误的屏蔽。方便错误查看