import { defineConfig } from "vite";
import uni from "@dcloudio/vite-plugin-uni";
import { execSync } from 'child_process';

// 获取当前git提交的ID
function getGitCommitId() {
  try {
    // 执行git命令获取当前提交的SHA值
    const commitId = execSync('git rev-parse HEAD').toString().trim();
    return commitId;
  } catch (error) {
    console.error('获取git提交ID失败:', error);
    return '';
  }
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [uni()],
  css: {
    preprocessorOptions: {
      scss: {
        silenceDeprecations: ['legacy-js-api','import'],
      },
    },
  },
  define: {
    __BUILD_GUID__: JSON.stringify(getGitCommitId()), //当前 git 提交的 id
    __BUILD_TIMESTAMP__: Date.now() //时间戳（数字）
  }
});
