vite.config.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { fileURLToPath, URL } from 'node:url'
  2. import vue from '@vitejs/plugin-vue'
  3. import vueJsx from '@vitejs/plugin-vue-jsx'
  4. import UnoCSS from 'unocss/vite'
  5. import AutoImport from 'unplugin-auto-import/vite'
  6. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
  7. import Components from 'unplugin-vue-components/vite'
  8. import DefineOptions from 'unplugin-vue-define-options/vite'
  9. import { defineConfig, loadEnv } from 'vite'
  10. import vitePluginBuildId from 'vite-plugin-build-id'
  11. import Inspect from 'vite-plugin-inspect'
  12. import svgLoader from 'vite-svg-loader'
  13. // https://vitejs.dev/config/
  14. export default defineConfig(({ mode }) => {
  15. const env = loadEnv(mode, process.cwd(), '')
  16. return {
  17. base: './',
  18. resolve: {
  19. alias: {
  20. '@': fileURLToPath(new URL('./src', import.meta.url)),
  21. },
  22. extensions: [
  23. '.mjs',
  24. '.js',
  25. '.ts',
  26. '.jsx',
  27. '.tsx',
  28. '.json',
  29. '.vue',
  30. '.less',
  31. ],
  32. },
  33. plugins: [
  34. vue(),
  35. vueJsx(),
  36. vitePluginBuildId(),
  37. svgLoader(),
  38. UnoCSS(),
  39. Components({
  40. resolvers: [AntDesignVueResolver({ importStyle: false })],
  41. directoryAsNamespace: true,
  42. }),
  43. AutoImport({
  44. imports: [
  45. 'vue',
  46. 'vue-router',
  47. 'pinia',
  48. {
  49. '@/gettext': [
  50. '$gettext',
  51. '$pgettext',
  52. '$ngettext',
  53. '$npgettext',
  54. ],
  55. },
  56. {
  57. '@/language': ['T'],
  58. },
  59. {
  60. '@/composables/useGlobalApp': ['useGlobalApp'],
  61. },
  62. {
  63. 'ant-design-vue': [
  64. 'App',
  65. ],
  66. },
  67. ],
  68. vueTemplate: true,
  69. eslintrc: {
  70. enabled: true,
  71. filepath: '.eslint-auto-import.mjs',
  72. },
  73. }),
  74. DefineOptions(),
  75. Inspect(),
  76. ],
  77. css: {
  78. preprocessorOptions: {
  79. less: {
  80. modifyVars: {
  81. 'border-radius-base': '5px',
  82. },
  83. javascriptEnabled: true,
  84. },
  85. },
  86. },
  87. server: {
  88. port: Number.parseInt(env.VITE_PORT) || 3002,
  89. proxy: {
  90. '/api': {
  91. target: env.VITE_PROXY_TARGET || 'http://localhost:9001',
  92. changeOrigin: true,
  93. secure: false,
  94. },
  95. },
  96. },
  97. build: {
  98. chunkSizeWarningLimit: 1500,
  99. },
  100. }
  101. })