vite.config.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import react from '@vitejs/plugin-react';
  2. import { defineConfig, transformWithEsbuild } from 'vite';
  3. import { vitePluginSemi } from '@douyinfe/vite-plugin-semi';
  4. // https://vitejs.dev/config/
  5. export default defineConfig({
  6. plugins: [
  7. {
  8. name: 'treat-js-files-as-jsx',
  9. async transform(code, id) {
  10. if (!/src\/.*\.js$/.test(id)) {
  11. return null;
  12. }
  13. // Use the exposed transform from vite, instead of directly
  14. // transforming with esbuild
  15. return transformWithEsbuild(code, id, {
  16. loader: 'jsx',
  17. jsx: 'automatic',
  18. });
  19. },
  20. },
  21. react(),
  22. vitePluginSemi({
  23. cssLayer: true
  24. })
  25. ],
  26. optimizeDeps: {
  27. force: true,
  28. esbuildOptions: {
  29. loader: {
  30. '.js': 'jsx',
  31. '.json': 'json',
  32. },
  33. },
  34. },
  35. build: {
  36. rollupOptions: {
  37. output: {
  38. manualChunks: {
  39. 'react-core': ['react', 'react-dom', 'react-router-dom'],
  40. 'semi-ui': ['@douyinfe/semi-icons', '@douyinfe/semi-ui'],
  41. semantic: ['semantic-ui-offline', 'semantic-ui-react'],
  42. visactor: ['@visactor/react-vchart', '@visactor/vchart'],
  43. tools: ['axios', 'history', 'marked'],
  44. 'react-components': [
  45. 'react-dropzone',
  46. 'react-fireworks',
  47. 'react-telegram-login',
  48. 'react-toastify',
  49. 'react-turnstile',
  50. ],
  51. i18n: [
  52. 'i18next',
  53. 'react-i18next',
  54. 'i18next-browser-languagedetector',
  55. ],
  56. },
  57. },
  58. },
  59. },
  60. server: {
  61. host: '0.0.0.0',
  62. proxy: {
  63. '/api': {
  64. target: 'http://localhost:3000',
  65. changeOrigin: true,
  66. },
  67. '/pg': {
  68. target: 'http://localhost:3000',
  69. changeOrigin: true,
  70. },
  71. },
  72. },
  73. });