vite.config.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import { Agent } from 'node:http'
  2. import { fileURLToPath, URL } from 'node:url'
  3. import vue from '@vitejs/plugin-vue'
  4. import vueJsx from '@vitejs/plugin-vue-jsx'
  5. import UnoCSS from 'unocss/vite'
  6. import AutoImport from 'unplugin-auto-import/vite'
  7. import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'
  8. import Components from 'unplugin-vue-components/vite'
  9. import DefineOptions from 'unplugin-vue-define-options/vite'
  10. import { defineConfig, loadEnv } from 'vite'
  11. import vitePluginBuildId from 'vite-plugin-build-id'
  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. ],
  65. css: {
  66. preprocessorOptions: {
  67. less: {
  68. modifyVars: {
  69. 'border-radius-base': '5px',
  70. },
  71. javascriptEnabled: true,
  72. },
  73. },
  74. },
  75. server: {
  76. port: Number.parseInt(env.VITE_PORT) || 3002,
  77. proxy: {
  78. '/api': {
  79. target: env.VITE_PROXY_TARGET || 'http://localhost:9000',
  80. changeOrigin: true,
  81. secure: false,
  82. ws: true,
  83. timeout: 60000,
  84. agent: new Agent({
  85. keepAlive: false,
  86. }),
  87. onProxyReq(proxyReq, req) {
  88. proxyReq.setHeader('Connection', 'keep-alive')
  89. if (req.headers.accept === 'text/event-stream') {
  90. proxyReq.setHeader('Cache-Control', 'no-cache')
  91. proxyReq.setHeader('Content-Type', 'text/event-stream')
  92. }
  93. },
  94. onProxyReqWs(proxyReq, req, socket) {
  95. socket.on('close', () => {
  96. proxyReq.destroy()
  97. })
  98. },
  99. },
  100. },
  101. },
  102. build: {
  103. chunkSizeWarningLimit: 1000,
  104. rollupOptions: {
  105. output: {
  106. manualChunks: {
  107. 'ace-editor': ['ace-builds'],
  108. },
  109. },
  110. },
  111. },
  112. }
  113. })