vite.config.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. dirs: ["./src/plugin"], // 自动扫描并导入 `src/plugin` 下的方法
  22. resolvers: [
  23. TDesignResolver({
  24. library: "vue-next",
  25. }),
  26. ],
  27. dts: "src/auto-imports.d.ts", // 自动生成类型声明文件
  28. }),
  29. Components({
  30. resolvers: [
  31. TDesignResolver({
  32. library: "vue-next",
  33. }),
  34. // 由于tdesign 官方未在unplugin-vue-components 处理自动导入指令的情况
  35. // 所以手动导入下
  36. {
  37. type: 'directive',
  38. resolve: (name) => {
  39. if (name === 'Loading') {
  40. return {
  41. name: 'vLoading',
  42. from: `tdesign-vue-next/esm/loading/directive`
  43. };
  44. } else {
  45. return;
  46. }
  47. },
  48. }
  49. ],
  50. directives: true
  51. }),
  52. createSvgIconsPlugin({
  53. // 指定需要缓存的图标文件夹
  54. iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
  55. // 指定symbolId格式
  56. symbolId: "[name]",
  57. /**
  58. * 自定义插入位置
  59. * @default: body-last
  60. */
  61. // inject?: 'body-last' | 'body-first'
  62. /**
  63. * custom dom id
  64. * @default: __svg__icons__dom__
  65. */
  66. // customDomId: '__svg__icons__dom__'
  67. }),
  68. zipBuildPlugin()
  69. ],
  70. css: {
  71. // css预处理器
  72. preprocessorOptions: {
  73. scss: {
  74. // 定义全局的scss变量
  75. // 给导入的路径最后加上 ;
  76. additionalData: `@import '@/styles/var.scss';`,
  77. },
  78. },
  79. },
  80. resolve: {
  81. alias: {
  82. "@": path.resolve(__dirname, "./src"),
  83. },
  84. },
  85. build: {
  86. outDir: ENV.VITE_APP_OUTDIR,
  87. },
  88. server:{
  89. port:8900,
  90. proxy:{
  91. '/v1': {
  92. // target: 'http://192.168.20.10:8912/v1',
  93. target: 'http://8.136.199.33:8900/v1',
  94. // target: 'http://8.136.199.33:7777/adminapi/',
  95. changeOrigin: true,
  96. rewrite: (path) => path.replace(/^\/v1/, ''),
  97. }
  98. }
  99. }
  100. };
  101. });