vite.config.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. },
  28. },
  29. },
  30. build: {
  31. rollupOptions: {
  32. output: {
  33. manualChunks: {
  34. 'react-core': ['react', 'react-dom', 'react-router-dom'],
  35. 'semi-ui': ['@douyinfe/semi-icons', '@douyinfe/semi-ui'],
  36. semantic: ['semantic-ui-offline', 'semantic-ui-react'],
  37. visactor: ['@visactor/react-vchart', '@visactor/vchart'],
  38. tools: ['axios', 'history', 'marked'],
  39. 'react-components': [
  40. 'react-dropzone',
  41. 'react-fireworks',
  42. 'react-telegram-login',
  43. 'react-toastify',
  44. 'react-turnstile',
  45. ],
  46. },
  47. },
  48. },
  49. },
  50. server: {
  51. proxy: {
  52. '/api': {
  53. target: 'http://localhost:3000',
  54. changeOrigin: true,
  55. },
  56. },
  57. },
  58. });