vite.config.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. Copyright (C) 2025 QuantumNous
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <https://www.gnu.org/licenses/>.
  13. For commercial licensing, please contact [email protected]
  14. */
  15. import react from '@vitejs/plugin-react';
  16. import { defineConfig, transformWithEsbuild } from 'vite';
  17. import pkg from '@douyinfe/vite-plugin-semi';
  18. const { vitePluginSemi } = pkg;
  19. // https://vitejs.dev/config/
  20. export default defineConfig({
  21. plugins: [
  22. {
  23. name: 'treat-js-files-as-jsx',
  24. async transform(code, id) {
  25. if (!/src\/.*\.js$/.test(id)) {
  26. return null;
  27. }
  28. // Use the exposed transform from vite, instead of directly
  29. // transforming with esbuild
  30. return transformWithEsbuild(code, id, {
  31. loader: 'jsx',
  32. jsx: 'automatic',
  33. });
  34. },
  35. },
  36. react(),
  37. vitePluginSemi({
  38. cssLayer: true,
  39. }),
  40. ],
  41. optimizeDeps: {
  42. force: true,
  43. esbuildOptions: {
  44. loader: {
  45. '.js': 'jsx',
  46. '.json': 'json',
  47. },
  48. },
  49. },
  50. build: {
  51. rollupOptions: {
  52. output: {
  53. manualChunks: {
  54. 'react-core': ['react', 'react-dom', 'react-router-dom'],
  55. 'semi-ui': ['@douyinfe/semi-icons', '@douyinfe/semi-ui'],
  56. tools: ['axios', 'history', 'marked'],
  57. 'react-components': [
  58. 'react-dropzone',
  59. 'react-fireworks',
  60. 'react-telegram-login',
  61. 'react-toastify',
  62. 'react-turnstile',
  63. ],
  64. i18n: [
  65. 'i18next',
  66. 'react-i18next',
  67. 'i18next-browser-languagedetector',
  68. ],
  69. },
  70. },
  71. },
  72. },
  73. server: {
  74. host: '0.0.0.0',
  75. proxy: {
  76. '/api': {
  77. target: 'http://localhost:3000',
  78. changeOrigin: true,
  79. },
  80. '/mj': {
  81. target: 'http://localhost:3000',
  82. changeOrigin: true,
  83. },
  84. '/pg': {
  85. target: 'http://localhost:3000',
  86. changeOrigin: true,
  87. },
  88. },
  89. },
  90. });