vite.config.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. vueTemplate: true,
  58. eslintrc: {
  59. enabled: true,
  60. filepath: '.eslint-auto-import.mjs',
  61. },
  62. }),
  63. DefineOptions(),
  64. Inspect(),
  65. ],
  66. css: {
  67. preprocessorOptions: {
  68. less: {
  69. modifyVars: {
  70. 'border-radius-base': '5px',
  71. },
  72. javascriptEnabled: true,
  73. },
  74. },
  75. },
  76. server: {
  77. port: Number.parseInt(env.VITE_PORT) || 3002,
  78. proxy: {
  79. '/api': {
  80. target: env.VITE_PROXY_TARGET || 'http://localhost:9000',
  81. changeOrigin: true,
  82. secure: false,
  83. ws: true,
  84. timeout: 60000,
  85. },
  86. },
  87. },
  88. build: {
  89. chunkSizeWarningLimit: 1000,
  90. rollupOptions: {
  91. output: {
  92. manualChunks: {
  93. 'ace-editor': ['ace-builds'],
  94. },
  95. },
  96. },
  97. },
  98. }
  99. })