vite.config.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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: isProduction ? './' : '/',
  10. plugins: [
  11. vue(),
  12. Components({
  13. resolvers: [
  14. AntDesignVueResolver({
  15. importStyle: false, // css in js
  16. })
  17. ],
  18. })
  19. ],
  20. resolve: {
  21. alias: {
  22. '@': path.resolve(__dirname, 'src')
  23. }
  24. },
  25. css: {
  26. preprocessorOptions: {
  27. less: {
  28. math: 'always',
  29. globalVars: {},
  30. modifyVars: {
  31. 'hack': 'true; @import "@/styles/variables.less";'
  32. }
  33. }
  34. }
  35. },
  36. server: {
  37. port: 3000,
  38. open: true,
  39. proxy: {
  40. // '/api': {
  41. // // target: 'https://jiasm.zfire.top/zfdapi/',
  42. // target: 'https://jiasm.zfire.top',
  43. // ws: true,
  44. // changeOrigin: true,
  45. // rewrite: (path) => path.replace(/^\/api/, '')
  46. // }
  47. }
  48. },
  49. build: {
  50. outDir: 'dist',
  51. assetsDir: 'assets',
  52. rollupOptions: {
  53. output: {
  54. // 确保资源路径正确
  55. chunkFileNames: 'assets/[name]-[hash].js',
  56. entryFileNames: 'assets/[name]-[hash].js',
  57. assetFileNames: 'assets/[name]-[hash].[ext]'
  58. }
  59. }
  60. }
  61. }
  62. })