vite.config.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. // https://vitejs.dev/config/
  9. export default defineConfig(({ mode }) => {
  10. const ENV = loadEnv(mode, process.cwd());
  11. return {
  12. base: ENV.VITE_APP_BASE_URL, // 若服务器不是将该项目放在根目录的则 需要此设置 和服务器上同名
  13. plugins: [
  14. vue(),
  15. AutoImport({
  16. resolvers: [
  17. TDesignResolver({
  18. library: "vue-next",
  19. }),
  20. ],
  21. }),
  22. Components({
  23. resolvers: [
  24. TDesignResolver({
  25. library: "vue-next",
  26. }),
  27. // 由于tdesign 官方未在unplugin-vue-components 处理自动导入指令的情况
  28. // 所以手动导入下
  29. {
  30. type: 'directive',
  31. resolve: (name) => {
  32. if (name === 'Loading') {
  33. return {
  34. name: 'vLoading',
  35. from: `tdesign-vue-next/esm/loading/directive`
  36. };
  37. } else {
  38. return;
  39. }
  40. },
  41. }
  42. ],
  43. directives: true
  44. }),
  45. createSvgIconsPlugin({
  46. // 指定需要缓存的图标文件夹
  47. iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
  48. // 指定symbolId格式
  49. symbolId: "[name]",
  50. /**
  51. * 自定义插入位置
  52. * @default: body-last
  53. */
  54. // inject?: 'body-last' | 'body-first'
  55. /**
  56. * custom dom id
  57. * @default: __svg__icons__dom__
  58. */
  59. // customDomId: '__svg__icons__dom__'
  60. }),
  61. ],
  62. css: {
  63. // css预处理器
  64. preprocessorOptions: {
  65. scss: {
  66. // 定义全局的scss变量
  67. // 给导入的路径最后加上 ;
  68. additionalData: `@import '@/styles/var.scss';`,
  69. },
  70. },
  71. },
  72. resolve: {
  73. alias: {
  74. "@": path.resolve(__dirname, "./src"),
  75. },
  76. },
  77. build: {
  78. outDir: ENV.VITE_APP_OUTDIR,
  79. },
  80. server:{
  81. port:8900,
  82. proxy:{
  83. '/v1': {
  84. target: 'http://8.136.199.33:8900/v1',
  85. changeOrigin: true,
  86. rewrite: (path) => path.replace(/^\/v1/, ''),
  87. }
  88. }
  89. }
  90. };
  91. });