vite.config.mjs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. export const r = (...args) => resolve(__dirname, '.', ...args)
  22. const removeModulePreloadPlugin = (keys) => {
  23. if (!keys || !keys.length) {
  24. return
  25. }
  26. return {
  27. name: 'remove-module-preload',
  28. transformIndexHtml: {
  29. enforce: 'after',
  30. transform(html, ctx) {
  31. let result = html
  32. keys.forEach((key) => {
  33. result = result.replace(new RegExp(`<link rel="modulepreload"?.*${key}?.*`), '')
  34. })
  35. return result
  36. }
  37. }
  38. }
  39. }
  40. export default defineConfig(({ command, mode }) => {
  41. const envConfig = loadEnv(mode, './')
  42. const alias = {
  43. '~': `${resolve(__dirname, './')}`,
  44. '@/': `${resolve(__dirname, 'src')}/`
  45. }
  46. return {
  47. server: {
  48. port: envConfig.VITE_PORT,
  49. proxy: {
  50. '/api': {
  51. target: envConfig.VITE_API_BASEURL,
  52. ws: false,
  53. changeOrigin: true,
  54. rewrite: (path) => path.replace(/^\/api/, '')
  55. }
  56. }
  57. },
  58. resolve: {
  59. alias
  60. },
  61. // 解决警告You are running the esm-bundler build of vue-i18n.
  62. define: {
  63. __VUE_I18N_FULL_INSTALL__: true,
  64. __VUE_I18N_LEGACY_API__: true,
  65. __VUE_I18N_PROD_DEVTOOLS__: true
  66. },
  67. build: {
  68. // sourcemap: true,
  69. manifest: true,
  70. brotliSize: false,
  71. rollupOptions: {
  72. output: {
  73. manualChunks: {
  74. echarts: ['echarts'],
  75. 'ant-design-vue': ['ant-design-vue'],
  76. vue: ['vue', 'vue-router', 'pinia', 'vue-i18n']
  77. }
  78. }
  79. },
  80. chunkSizeWarningLimit: 1000
  81. },
  82. plugins: [
  83. vue({
  84. script: {
  85. refTransform: true
  86. }
  87. }),
  88. viteCompression(),
  89. vueSetupExtend(),
  90. VueJSX(),
  91. AutoImport({
  92. imports: ['vue'],
  93. dirs: ['./src/utils/permission'],
  94. dts: r('src/auto-imports.d.ts')
  95. }),
  96. // 组件按需引入
  97. Components({
  98. dirs: [r('src/components')],
  99. dts: false,
  100. resolvers: []
  101. }),
  102. visualizer()
  103. ],
  104. css: {
  105. preprocessorOptions: {
  106. less: {
  107. javascriptEnabled: true,
  108. plugins: [new Less2CssVariablePlugin()]
  109. }
  110. }
  111. },
  112. optimizeDeps: {
  113. include: ['dayjs/locale/zh-cn']
  114. }
  115. }
  116. })