vite.config.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. import path from 'path';
  19. const { vitePluginSemi } = pkg;
  20. // https://vitejs.dev/config/
  21. export default defineConfig({
  22. resolve: {
  23. alias: {
  24. '@': path.resolve(__dirname, './src'),
  25. },
  26. },
  27. plugins: [
  28. {
  29. name: 'treat-js-files-as-jsx',
  30. async transform(code, id) {
  31. if (!/src\/.*\.js$/.test(id)) {
  32. return null;
  33. }
  34. // Use the exposed transform from vite, instead of directly
  35. // transforming with esbuild
  36. return transformWithEsbuild(code, id, {
  37. loader: 'jsx',
  38. jsx: 'automatic',
  39. });
  40. },
  41. },
  42. react(),
  43. vitePluginSemi({
  44. cssLayer: true,
  45. }),
  46. ],
  47. optimizeDeps: {
  48. force: true,
  49. esbuildOptions: {
  50. loader: {
  51. '.js': 'jsx',
  52. '.json': 'json',
  53. },
  54. },
  55. },
  56. build: {
  57. rollupOptions: {
  58. output: {
  59. manualChunks: {
  60. 'react-core': ['react', 'react-dom', 'react-router-dom'],
  61. 'semi-ui': ['@douyinfe/semi-icons', '@douyinfe/semi-ui'],
  62. tools: ['axios', 'history', 'marked'],
  63. 'react-components': [
  64. 'react-dropzone',
  65. 'react-fireworks',
  66. 'react-telegram-login',
  67. 'react-toastify',
  68. 'react-turnstile',
  69. ],
  70. i18n: [
  71. 'i18next',
  72. 'react-i18next',
  73. 'i18next-browser-languagedetector',
  74. ],
  75. },
  76. },
  77. },
  78. },
  79. server: {
  80. host: '0.0.0.0',
  81. proxy: {
  82. '/api': {
  83. target: 'http://localhost:3000',
  84. changeOrigin: true,
  85. },
  86. '/mj': {
  87. target: 'http://localhost:3000',
  88. changeOrigin: true,
  89. },
  90. '/pg': {
  91. target: 'http://localhost:3000',
  92. changeOrigin: true,
  93. },
  94. },
  95. },
  96. });