vite.config.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import { defineConfig } from 'vite'
  2. import vue from '@vitejs/plugin-vue'
  3. import path from 'path'
  4. import Components from 'unplugin-vue-components/vite'
  5. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
  6. export default defineConfig(({ mode }) => {
  7. const isProduction = mode === 'production'
  8. return {
  9. // 根据环境设置不同的base路径
  10. // 开发环境使用根路径'/',方便本地开发访问
  11. // 生产环境使用'/overseas-mall/',与nginx配置匹配
  12. base: isProduction ? '/overseas-mall/' : '/',
  13. plugins: [
  14. vue(),
  15. Components({
  16. resolvers: [
  17. AntDesignVueResolver({
  18. importStyle: false, // css in js
  19. })
  20. ],
  21. })
  22. ],
  23. resolve: {
  24. alias: {
  25. '@': path.resolve(__dirname, 'src')
  26. }
  27. },
  28. css: {
  29. preprocessorOptions: {
  30. less: {
  31. math: 'always',
  32. globalVars: {},
  33. modifyVars: {
  34. 'hack': 'true; @import "@/styles/variables.less";'
  35. }
  36. }
  37. }
  38. },
  39. server: {
  40. port: 8088,
  41. open: true,
  42. proxy: {
  43. // '/api': {
  44. // // target: 'https://jiasm.zfire.top/zfdapi/',
  45. // target: 'https://jiasm.zfire.top',
  46. // ws: true,
  47. // changeOrigin: true,
  48. // rewrite: (path) => path.replace(/^\/api/, '')
  49. // }
  50. }
  51. },
  52. build: {
  53. outDir: 'dist',
  54. assetsDir: 'assets',
  55. rollupOptions: {
  56. output: {
  57. // 确保资源路径正确
  58. chunkFileNames: 'assets/[name]-[hash].js',
  59. entryFileNames: 'assets/[name]-[hash].js',
  60. assetFileNames: 'assets/[name]-[hash].[ext]'
  61. }
  62. }
  63. }
  64. }
  65. })