vite.config.ts 2.4 KB

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