vite.config.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 support@quantumnous.com
  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. visactor: ['@visactor/react-vchart', '@visactor/vchart'],
  57. tools: ['axios', 'history', 'marked'],
  58. 'react-components': [
  59. 'react-dropzone',
  60. 'react-fireworks',
  61. 'react-telegram-login',
  62. 'react-toastify',
  63. 'react-turnstile',
  64. ],
  65. i18n: [
  66. 'i18next',
  67. 'react-i18next',
  68. 'i18next-browser-languagedetector',
  69. ],
  70. },
  71. },
  72. },
  73. },
  74. server: {
  75. host: '0.0.0.0',
  76. proxy: {
  77. '/api': {
  78. target: 'http://localhost:3000',
  79. changeOrigin: true,
  80. },
  81. '/mj': {
  82. target: 'http://localhost:3000',
  83. changeOrigin: true,
  84. },
  85. '/pg': {
  86. target: 'http://localhost:3000',
  87. changeOrigin: true,
  88. },
  89. },
  90. },
  91. });