vite.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 { createSvgIconsPlugin } from "vite-plugin-svg-icons";
  7. import AutoImport from 'unplugin-auto-import/vite';
  8. import Components from 'unplugin-vue-components/vite';
  9. import { TDesignResolver } from 'unplugin-vue-components/resolvers';
  10. import zipBuildPlugin from './zipBuildPlugin';
  11. import compress from 'vite-plugin-compression'
  12. // https://vitejs.dev/config/
  13. export default defineConfig(({ mode }) => {
  14. const ENV = loadEnv(mode, process.cwd());
  15. return {
  16. base: ENV.VITE_APP_BASE_URL, // 若服务器不是将该项目放在根目录的则 需要此设置 和服务器上同名
  17. plugins: [
  18. vue(),
  19. AutoImport({
  20. // 自动导入 Vue 相关函数,如:ref, reactive, toRef 等
  21. imports: ["vue"],
  22. resolvers: [TDesignResolver({
  23. library: 'mobile-vue'
  24. })],
  25. }),
  26. Components({
  27. resolvers: [TDesignResolver({
  28. library: 'mobile-vue'
  29. })],
  30. }),
  31. createSvgIconsPlugin({
  32. // 指定需要缓存的图标文件夹
  33. iconDirs: [path.resolve(process.cwd(), "src/assets/svg")],
  34. // 指定symbolId格式
  35. symbolId: "[name]",
  36. /**
  37. * 自定义插入位置
  38. * @default: body-last
  39. */
  40. // inject?: 'body-last' | 'body-first'
  41. /**
  42. * custom dom id
  43. * @default: __svg__icons__dom__
  44. */
  45. // customDomId: '__svg__icons__dom__'
  46. }),
  47. compress({
  48. algorithm: 'gzip',
  49. ext: '.gz'
  50. }),
  51. {
  52. name: 'custom-zip-plugin',
  53. apply: 'build',
  54. closeBundle() {
  55. setTimeout(() => {
  56. const plugin = zipBuildPlugin(ENV.VITE_APP_OUTDIR);
  57. return plugin.closeBundle.handler();
  58. }, 1000);
  59. }
  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: 8708,
  82. proxy: {
  83. "/api": {
  84. target: "http://8.136.199.33:8709/api",
  85. changeOrigin: true,
  86. rewrite: (path) => path.replace(/^\/api/, ""),
  87. },
  88. },
  89. },
  90. };
  91. });