You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

113 line
2.9 KiB

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