vite.config.js 2.4 KB

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