vite.config.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { defineConfig, loadEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import path from "path";
  4. import Icons from "unplugin-icons/vite";
  5. import IconsResolver from "unplugin-icons/resolver";
  6. import AutoImport from "unplugin-auto-import/vite";
  7. import Components from "unplugin-vue-components/vite";
  8. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  9. import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
  10. // https://vitejs.dev/config/
  11. export default defineConfig(({ mode }) => {
  12. const ENV = loadEnv(mode, process.cwd());
  13. return {
  14. base: ENV.VITE_APP_BASE_URL, // 若服务器不是将该项目放在根目录的则 需要此设置 和服务器上同名
  15. plugins: [
  16. vue(),
  17. AutoImport({
  18. // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
  19. imports: ["vue"],
  20. resolvers: [
  21. ElementPlusResolver(),
  22. // 自动导入图标组件
  23. IconsResolver({
  24. prefix: "Icon",
  25. }),
  26. ],
  27. }),
  28. Components({
  29. resolvers: [
  30. ElementPlusResolver(),
  31. // 自动注册图标组件
  32. IconsResolver({
  33. enabledCollections: ["ep"],
  34. }),
  35. {
  36. type: 'directive',
  37. resolve: (name) => {
  38. if (name === 'Loading') {
  39. return {
  40. name: 'vLoading',
  41. from: `element-plus/es/components/loading/src/directive`
  42. };
  43. } else {
  44. return;
  45. }
  46. },
  47. }
  48. ],
  49. directives: true
  50. }),
  51. Icons({
  52. autoInstall: true,
  53. }),
  54. createSvgIconsPlugin({
  55. // 指定需要缓存的图标文件夹
  56. iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
  57. // 指定symbolId格式
  58. symbolId: "[name]",
  59. /**
  60. * 自定义插入位置
  61. * @default: body-last
  62. */
  63. // inject?: 'body-last' | 'body-first'
  64. /**
  65. * custom dom id
  66. * @default: __svg__icons__dom__
  67. */
  68. // customDomId: '__svg__icons__dom__'
  69. }),
  70. ],
  71. css: {
  72. // css预处理器
  73. preprocessorOptions: {
  74. scss: {
  75. // 定义全局的scss变量
  76. // 给导入的路径最后加上 ;
  77. // additionalData: `@import '@/styles/var.scss';`,
  78. },
  79. },
  80. },
  81. resolve: {
  82. alias: {
  83. "@": path.resolve(__dirname, "./src"),
  84. },
  85. },
  86. build: {
  87. outDir: ENV.VITE_APP_OUTDIR,
  88. },
  89. server: {
  90. port: 8715,
  91. proxy: {
  92. "/v1": {
  93. target: "http://192.168.77.27:8715/adminapi",
  94. changeOrigin: true,
  95. rewrite: (path) => path.replace(/^\/v1/, ""),
  96. },
  97. },
  98. },
  99. };
  100. });