vite.config.js 2.8 KB

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