import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import uni from '@dcloudio/vite-plugin-uni'

export default defineConfig({
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  plugins: [
    uni(),
  ],
  /** 构建时常量注入：__BUILD_TIME__ 在源码中展开为精确的打包时刻字符串 */
  define: (() => {
    const d = new Date();
    const pad = (n) => String(n).padStart(2, '0');
    // 格式：YYYY.MMDD.HHmm，如 2026.0514.1530
    const version = `${d.getFullYear()}.${pad(d.getMonth() + 1)}${pad(d.getDate())}.${pad(d.getHours())}${pad(d.getMinutes())}`;
    return { __BUILD_TIME__: JSON.stringify(version) };
  })(),
  
})


