vite.config.mjs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /**
  2. * Copyright [2022] [https://www.xiaonuo.vip]
  3. * Snowy采用APACHE LICENSE 2.0开源协议,您在使用过程中,需要注意以下几点:
  4. * 1.请不要删除和修改根目录下的LICENSE文件。
  5. * 2.请不要删除和修改Snowy源码头部的版权声明。
  6. * 3.本项目代码可免费商业使用,商业使用请保留源码和相关描述文件的项目出处,作者声明等。
  7. * 4.分发源码时候,请注明软件出处 https://www.xiaonuo.vip
  8. * 5.不可二次分发开源参与同类竞品,如有想法可联系团队xiaonuobase@qq.com商议合作。
  9. * 6.若您的项目无法满足以上几点,需要更多功能代码,获取Snowy商业授权许可,请在官网购买授权,地址为 https://www.xiaonuo.vip
  10. */
  11. import { resolve } from 'path'
  12. import { defineConfig, loadEnv } from 'vite'
  13. import vue from '@vitejs/plugin-vue'
  14. import Components from 'unplugin-vue-components/vite'
  15. import VueJSX from '@vitejs/plugin-vue-jsx'
  16. import AutoImport from 'unplugin-auto-import/vite'
  17. import vueSetupExtend from 'vite-plugin-vue-setup-extend'
  18. import { visualizer } from 'rollup-plugin-visualizer'
  19. import Less2CssVariablePlugin from 'antd-less-to-css-variable'
  20. import viteCompression from 'vite-plugin-compression'
  21. // ant-design-vue 的 less 变量,通过兼容包将 v4 变量转译成 v3 版本,并通过 less-loader 注入
  22. import { theme } from 'ant-design-vue/lib';
  23. import convertLegacyToken from 'ant-design-vue/lib/theme/convertLegacyToken';
  24. const { defaultAlgorithm, defaultSeed } = theme;
  25. const mapToken = defaultAlgorithm(defaultSeed);
  26. const v3Token = convertLegacyToken.default(mapToken);
  27. export const r = (...args) => resolve(__dirname, '.', ...args)
  28. export default defineConfig(({ command, mode }) => {
  29. const envConfig = loadEnv(mode, './')
  30. const alias = {
  31. '~': `${resolve(__dirname, './')}`,
  32. '@/': `${resolve(__dirname, 'src')}/`
  33. }
  34. return {
  35. server: {
  36. port: envConfig.VITE_PORT,
  37. proxy: {
  38. '/api': {
  39. target: envConfig.VITE_API_BASEURL,
  40. ws: false,
  41. changeOrigin: true,
  42. rewrite: (path) => path.replace(/^\/api/, '')
  43. }
  44. }
  45. },
  46. resolve: {
  47. alias
  48. },
  49. // 解决警告You are running the esm-bundler build of vue-i18n.
  50. define: {
  51. __VUE_I18N_FULL_INSTALL__: true,
  52. __VUE_I18N_LEGACY_API__: true,
  53. __VUE_I18N_PROD_DEVTOOLS__: true,
  54. __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: true
  55. },
  56. // base: '/yqyc/',
  57. build: {
  58. // sourcemap: true,
  59. outDir: "yqyc-web",
  60. manifest: true,
  61. brotliSize: false,
  62. rollupOptions: {
  63. output: {
  64. manualChunks: {
  65. echarts: ['echarts'],
  66. 'ant-design-vue': ['ant-design-vue'],
  67. vue: ['vue', 'vue-router', 'pinia', 'vue-i18n']
  68. }
  69. }
  70. },
  71. chunkSizeWarningLimit: 1000
  72. },
  73. plugins: [
  74. vue({
  75. script: {
  76. refTransform: true
  77. }
  78. }),
  79. viteCompression(),
  80. vueSetupExtend(),
  81. VueJSX(),
  82. AutoImport({
  83. imports: ['vue'],
  84. dirs: ['./src/utils/permission'],
  85. dts: r('src/auto-imports.d.ts')
  86. }),
  87. // 组件按需引入
  88. Components({
  89. dirs: [r('src/components')],
  90. dts: false,
  91. resolvers: []
  92. }),
  93. visualizer()
  94. ],
  95. css: {
  96. preprocessorOptions: {
  97. less: {
  98. javascriptEnabled: true,
  99. plugins: [new Less2CssVariablePlugin({
  100. // TODO:有必要用的情况下,是否需要传入 variables,可能会造成重复引用
  101. variables: { ...v3Token }
  102. })],
  103. modifyVars: v3Token
  104. }
  105. }
  106. },
  107. optimizeDeps: {}
  108. }
  109. })