From b256a3e0f57ed3883b1b68545d71adf0bc0a08c3 Mon Sep 17 00:00:00 2001 From: Soybean Date: Fri, 14 Jun 2024 00:01:37 +0800 Subject: [PATCH] optimize(projects): get buildTime with timezone 'Asia/Shanghai' --- build/config/index.ts | 1 + build/config/time.ts | 12 ++++++++++++ vite.config.ts | 5 ++--- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 build/config/time.ts diff --git a/build/config/index.ts b/build/config/index.ts index 9bcd868..8a9621a 100644 --- a/build/config/index.ts +++ b/build/config/index.ts @@ -1 +1,2 @@ export * from './proxy'; +export * from './time'; diff --git a/build/config/time.ts b/build/config/time.ts new file mode 100644 index 0000000..3b57146 --- /dev/null +++ b/build/config/time.ts @@ -0,0 +1,12 @@ +import dayjs from 'dayjs'; +import utc from 'dayjs/plugin/utc'; +import timezone from 'dayjs/plugin/timezone'; + +export function getBuildTime() { + dayjs.extend(utc); + dayjs.extend(timezone); + + const buildTime = dayjs.tz(Date.now(), 'Asia/Shanghai').format('YYYY-MM-DD HH:mm:ss'); + + return buildTime; +} diff --git a/vite.config.ts b/vite.config.ts index c3ea6d0..218d28c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,14 +1,13 @@ import process from 'node:process'; import { URL, fileURLToPath } from 'node:url'; import { defineConfig, loadEnv } from 'vite'; -import dayjs from 'dayjs'; import { setupVitePlugins } from './build/plugins'; -import { createViteProxy } from './build/config'; +import { createViteProxy, getBuildTime } from './build/config'; export default defineConfig(configEnv => { const viteEnv = loadEnv(configEnv.mode, process.cwd()) as unknown as Env.ImportMeta; - const buildTime = dayjs().format('YYYY-MM-DD HH:mm:ss'); + const buildTime = getBuildTime(); return { base: viteEnv.VITE_BASE_URL,