市场夺宝奇兵
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.3 KiB

  1. import { fileURLToPath, URL } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueDevTools from 'vite-plugin-vue-devtools'
  5. // https://vite.dev/config/
  6. export default defineConfig(({ mode, command }) => {
  7. // 加载环境变量
  8. const env = loadEnv(mode, process.cwd(), '')
  9. const outDirMap = {
  10. development: 'dist-test',
  11. product: 'dist-prod'
  12. }
  13. return {
  14. // 确保基础路径正确
  15. base: './',
  16. plugins: [
  17. vue(),
  18. vueDevTools(),
  19. ],
  20. resolve: {
  21. alias: {
  22. '@': fileURLToPath(new URL('./src', import.meta.url))
  23. },
  24. },
  25. build: {
  26. outDir: outDirMap[mode] || 'dist',
  27. rollupOptions: {
  28. input: {
  29. main: './index.html',
  30. download: './hcdbqb-download.html',
  31. guide: './hcdbqb-guide.html',
  32. management: './hcdbqb-management.html'
  33. },
  34. output: {
  35. manualChunks: undefined,
  36. chunkFileNames: 'assets/[name]-[hash].js',
  37. entryFileNames: 'assets/[name]-[hash].js'
  38. }
  39. }
  40. },
  41. server: {
  42. port: 5173,
  43. open: true
  44. },
  45. // 确保环境变量在构建时被正确处理
  46. define: {
  47. 'import.meta.env.VITE_API_BASE_URL': JSON.stringify(env.VITE_API_BASE_URL),
  48. 'import.meta.env.VITE_APP_ENV': JSON.stringify(env.VITE_APP_ENV)
  49. }
  50. }
  51. })