vite.config.js 1.7 KB

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