vite.config.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import path from 'node:path'
  2. import Vue from '@vitejs/plugin-vue'
  3. import VueJsx from '@vitejs/plugin-vue-jsx'
  4. import Unocss from 'unocss/vite'
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
  7. import Components from 'unplugin-vue-components/vite'
  8. import { defineConfig, loadEnv } from 'vite'
  9. import removeNoMatch from 'vite-plugin-router-warn'
  10. import VueDevTools from 'vite-plugin-vue-devtools'
  11. import { pluginIcons, pluginPagePathes } from './build/plugin-isme'
  12. export default defineConfig(({ mode }) => {
  13. const viteEnv = loadEnv(mode, process.cwd())
  14. const { VITE_PUBLIC_PATH, VITE_PROXY_TARGET } = viteEnv
  15. return {
  16. base: VITE_PUBLIC_PATH || '/',
  17. plugins: [
  18. Vue(),
  19. VueJsx(),
  20. VueDevTools(),
  21. Unocss(),
  22. AutoImport({
  23. imports: ['vue', 'vue-router'],
  24. dts: false,
  25. }),
  26. Components({
  27. resolvers: [NaiveUiResolver()],
  28. dts: false,
  29. }),
  30. // 自定义插件,用于生成页面文件的path,并添加到虚拟模块
  31. pluginPagePathes(),
  32. // 自定义插件,用于生成自定义icon,并添加到虚拟模块
  33. pluginIcons(),
  34. // 移除非必要的vue-router动态路由警告: No match found for location with path
  35. removeNoMatch(),
  36. ],
  37. resolve: {
  38. alias: {
  39. '@': path.resolve(process.cwd(), 'src'),
  40. '~': path.resolve(process.cwd()),
  41. },
  42. },
  43. server: {
  44. host: '0.0.0.0',
  45. port: 3200,
  46. open: false,
  47. proxy: {
  48. '/api': {
  49. target: VITE_PROXY_TARGET,
  50. changeOrigin: true,
  51. rewrite: path => path.replace(/^\/api/, ''),
  52. secure: false,
  53. configure: (proxy, options) => {
  54. // 配置此项可在响应头中看到请求的真实地址
  55. proxy.on('proxyRes', (proxyRes, req) => {
  56. proxyRes.headers['x-real-url'] = new URL(req.url || '', options.target)?.href || ''
  57. })
  58. },
  59. },
  60. },
  61. },
  62. build: {
  63. chunkSizeWarningLimit: 1024, // chunk 大小警告的限制(单位kb)
  64. rollupOptions: {
  65. input: {
  66. main: path.resolve(__dirname, 'index.html'),
  67. mobile: path.resolve(__dirname, 'swkzMobile.html'),
  68. },
  69. },
  70. },
  71. }
  72. })