vite.config.js 2.6 KB

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