From b3300e39391b0d0436e4e01886f123de44f5e97d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B4=9B=E6=B4=9B=E5=B8=8C=E9=9B=85?= Date: Fri, 26 Apr 2024 22:14:07 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4=E6=9A=B4=E9=9C=B2=E7=9A=84?= =?UTF-8?q?=E8=BF=87=E5=A4=9A=E7=8E=AF=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/login/index.vue | 2 +- typings/env.d.ts | 72 +++++++++++++++++++-------------------- vite.config.ts | 7 ++-- 3 files changed, 41 insertions(+), 40 deletions(-) diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 5e915ef..2071665 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -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}` })() diff --git a/typings/env.d.ts b/typings/env.d.ts index 00a3467..2e500c2 100644 --- a/typings/env.d.ts +++ b/typings/env.d.ts @@ -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 // 更多环境变量... } diff --git a/vite.config.ts b/vite.config.ts index 454dc0f..44fc01e 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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 可以禁用开发服务器错误的屏蔽。方便错误查看