vite.config.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {fileURLToPath, URL} from 'node:url'
  2. import {defineConfig} from 'vite'
  3. import config from './src/config'
  4. import useVitePlugins from './vite-plugins'
  5. let prefixKeys = Object.keys(config).filter(i => i.includes('Prefix'))
  6. let proxyObj = prefixKeys.reduce((r, i) => {
  7. let prefix = config[i]
  8. r[prefix] = {
  9. target: config.proxyLocation + prefix,
  10. ws: true,
  11. changeOrigin: true,
  12. rewrite: path => path.replace(new RegExp('^' + prefix), ''),
  13. timeout: 10000000,
  14. }
  15. return r
  16. }, {})
  17. // https://vitejs.dev/config/
  18. export default defineConfig({
  19. base: './',
  20. plugins: useVitePlugins(),
  21. resolve: {
  22. alias: {
  23. '@': fileURLToPath(new URL('./src', import.meta.url)),
  24. }
  25. },
  26. css: {
  27. preprocessorOptions: {
  28. scss: {
  29. additionalData: `@use "@/assets/styles/element/index.scss" as *;`,
  30. },
  31. },
  32. },
  33. // 开发环境代理配置,请更换target为后端服务器地址
  34. server: {
  35. port: 5173,
  36. proxy: proxyObj,
  37. },
  38. build: {
  39. // 当生产环境浏览器版本较低时,请改为es2015
  40. target: 'modules'
  41. }
  42. })