vite.config.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import { defineConfig, loadEnv } from "vite";
  2. import vue from "@vitejs/plugin-vue";
  3. import path from "path";
  4. import AutoImport from "unplugin-auto-import/vite";
  5. import Components from "unplugin-vue-components/vite";
  6. import { TDesignResolver } from "unplugin-vue-components/resolvers";
  7. import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  8. import zipBuildPlugin from './zipBuildPlugin';
  9. import vueJsx from '@vitejs/plugin-vue-jsx';
  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. vueJsx(),
  18. AutoImport({
  19. // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
  20. imports: ["vue"],
  21. resolvers: [
  22. TDesignResolver({
  23. library: "vue-next",
  24. }),
  25. ],
  26. }),
  27. Components({
  28. resolvers: [
  29. TDesignResolver({
  30. library: "vue-next",
  31. }),
  32. // 由于tdesign 官方未在unplugin-vue-components 处理自动导入指令的情况
  33. // 所以手动导入下
  34. {
  35. type: 'directive',
  36. resolve: (name) => {
  37. if (name === 'Loading') {
  38. return {
  39. name: 'vLoading',
  40. from: `tdesign-vue-next/esm/loading/directive`
  41. };
  42. } else {
  43. return;
  44. }
  45. },
  46. }
  47. ],
  48. directives: true
  49. }),
  50. createSvgIconsPlugin({
  51. // 指定需要缓存的图标文件夹
  52. iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
  53. // 指定symbolId格式
  54. symbolId: "[name]",
  55. /**
  56. * 自定义插入位置
  57. * @default: body-last
  58. */
  59. // inject?: 'body-last' | 'body-first'
  60. /**
  61. * custom dom id
  62. * @default: __svg__icons__dom__
  63. */
  64. // customDomId: '__svg__icons__dom__'
  65. }),
  66. zipBuildPlugin()
  67. ],
  68. css: {
  69. // css预处理器
  70. preprocessorOptions: {
  71. scss: {
  72. // 定义全局的scss变量
  73. // 给导入的路径最后加上 ;
  74. additionalData: `@import '@/styles/var.scss';`,
  75. },
  76. },
  77. },
  78. resolve: {
  79. alias: {
  80. "@": path.resolve(__dirname, "./src"),
  81. },
  82. },
  83. build: {
  84. outDir: ENV.VITE_APP_OUTDIR,
  85. },
  86. server:{
  87. port:8901,
  88. proxy:{
  89. '/v1': {
  90. target: 'http://8.136.199.33:8901/v1',
  91. changeOrigin: true,
  92. rewrite: (path) => path.replace(/^\/v1/, ''),
  93. }
  94. }
  95. }
  96. };
  97. });