vite.config.ts 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. vueJsx(),
  52. vitePluginBuildId(),
  53. svgLoader(),
  54. Components({
  55. resolvers: [AntDesignVueResolver({ importStyle: false })],
  56. directoryAsNamespace: true,
  57. }),
  58. AutoImport({
  59. imports: ['vue', 'vue-router', 'pinia'],
  60. vueTemplate: true,
  61. }),
  62. DefineOptions(),
  63. ],
  64. css: {
  65. preprocessorOptions: {
  66. less: {
  67. modifyVars: {
  68. 'border-radius-base': '5px',
  69. },
  70. javascriptEnabled: true,
  71. },
  72. },
  73. },
  74. server: {
  75. proxy: {
  76. '/api': {
  77. target: env.VITE_PROXY_TARGET || 'http://localhost:9000',
  78. changeOrigin: true,
  79. secure: false,
  80. ws: true,
  81. },
  82. },
  83. },
  84. build: {
  85. chunkSizeWarningLimit: 1000,
  86. },
  87. }
  88. })