vite.config.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { fileURLToPath, URL } from 'url'
  2. import { defineConfig } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import Components from 'unplugin-vue-components/vite'
  7. import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
  8. import { createStyleImportPlugin, ElementPlusResolve } from 'vite-plugin-style-import'
  9. import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
  10. import vueSetupExtend from 'vite-plugin-vue-setup-extend'
  11. // https://vitejs.dev/config/
  12. export default defineConfig({
  13. base: './', // 修改为相对路径
  14. server: {
  15. host: '0.0.0.0',
  16. cors: true // 允许跨域
  17. },
  18. plugins: [
  19. vue(),
  20. vueJsx(),
  21. AutoImport({
  22. imports: ['vue', 'vue-router'],
  23. resolvers: [ElementPlusResolver()],
  24. eslintrc: {
  25. enabled: true
  26. }
  27. }),
  28. Components({
  29. directoryAsNamespace: true,
  30. resolvers: [ElementPlusResolver()]
  31. }),
  32. createStyleImportPlugin({
  33. resolves: [ElementPlusResolve()]
  34. }),
  35. createSvgIconsPlugin({
  36. // 配置路劲在你的src里的svg存放文件
  37. iconDirs: [fileURLToPath(new URL('./src/assets/icons', import.meta.url))],
  38. symbolId: 'local-icon-[dir]-[name]'
  39. }),
  40. vueSetupExtend()
  41. ],
  42. resolve: {
  43. alias: {
  44. '@': fileURLToPath(new URL('./src', import.meta.url))
  45. }
  46. },
  47. build: {
  48. rollupOptions: {
  49. manualChunks(id) {
  50. if (id.includes('node_modules')) {
  51. return id.toString().split('node_modules/')[1].split('/')[0].toString()
  52. }
  53. }
  54. }
  55. }
  56. })