vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import { URL, fileURLToPath } from 'node:url'
  2. import { defineConfig, loadEnv } from 'vite'
  3. import vue from '@vitejs/plugin-vue'
  4. import Components from 'unplugin-vue-components/vite'
  5. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
  6. import vueJsx from '@vitejs/plugin-vue-jsx'
  7. import vitePluginBuildId from 'vite-plugin-build-id'
  8. import svgLoader from 'vite-svg-loader'
  9. import AutoImport from 'unplugin-auto-import/vite'
  10. import DefineOptions from 'unplugin-vue-define-options/vite'
  11. function fixAntdvWarningPlugin() {
  12. return {
  13. name: 'fix-antd-vue-warning', //
  14. transform(code: string, id: string) {
  15. // replace antdv js only
  16. if (id.includes('ant-design-vue/es/_util/hooks/_vueuse')) {
  17. // replace /* #__PURE__ */ with empty string
  18. const newCode = code.replace(/\/\* #__PURE__ \*\//g, '')
  19. return {
  20. code: newCode,
  21. map: null,
  22. }
  23. }
  24. },
  25. }
  26. }
  27. // https://vitejs.dev/config/
  28. export default defineConfig(({ mode }) => {
  29. // eslint-disable-next-line n/prefer-global/process
  30. const env = loadEnv(mode, process.cwd(), '')
  31. return {
  32. base: './',
  33. resolve: {
  34. alias: {
  35. '@': fileURLToPath(new URL('./src', import.meta.url)),
  36. },
  37. extensions: [
  38. '.mjs',
  39. '.js',
  40. '.ts',
  41. '.jsx',
  42. '.tsx',
  43. '.json',
  44. '.vue',
  45. '.less',
  46. ],
  47. },
  48. plugins: [
  49. fixAntdvWarningPlugin(),
  50. vue({
  51. script: {
  52. defineModel: true,
  53. },
  54. }),
  55. vueJsx(),
  56. vitePluginBuildId(),
  57. svgLoader(),
  58. Components({
  59. resolvers: [AntDesignVueResolver({ importStyle: false })],
  60. directoryAsNamespace: true,
  61. }),
  62. AutoImport({
  63. imports: ['vue', 'vue-router', 'pinia'],
  64. vueTemplate: true,
  65. }),
  66. DefineOptions(),
  67. ],
  68. css: {
  69. preprocessorOptions: {
  70. less: {
  71. modifyVars: {
  72. 'border-radius-base': '5px',
  73. },
  74. javascriptEnabled: true,
  75. },
  76. },
  77. },
  78. server: {
  79. proxy: {
  80. '/api': {
  81. target: env.VITE_PROXY_TARGET || 'http://localhost:9000',
  82. changeOrigin: true,
  83. secure: false,
  84. ws: true,
  85. },
  86. },
  87. },
  88. build: {
  89. chunkSizeWarningLimit: 1000,
  90. },
  91. }
  92. })