Skip to content

Commit

Permalink
optimize(projects): get buildTime with timezone 'Asia/Shanghai'
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jun 13, 2024
1 parent b5a723c commit 069fa8a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions build/config/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './proxy';
export * from './time';
12 changes: 12 additions & 0 deletions build/config/time.ts
Original file line number Diff line number Diff line change
@@ -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;
}
5 changes: 2 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down

0 comments on commit 069fa8a

Please sign in to comment.