vite.config.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import { defineConfig, transformWithEsbuild } from 'vite';
  2. import react from '@vitejs/plugin-react';
  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 (!id.match(/src\/.*\.js$/)) return null
  10. // Use the exposed transform from vite, instead of directly
  11. // transforming with esbuild
  12. return transformWithEsbuild(code, id, {
  13. loader: 'jsx',
  14. jsx: 'automatic',
  15. })
  16. },
  17. },
  18. react(),
  19. ],
  20. optimizeDeps: {
  21. force: true,
  22. esbuildOptions: {
  23. loader: {
  24. '.js': 'jsx',
  25. },
  26. },
  27. },
  28. build: {
  29. rollupOptions: {
  30. output: {
  31. manualChunks: {
  32. 'react-core': ['react', 'react-dom', 'react-router-dom'],
  33. 'semi-ui': ['@douyinfe/semi-icons', '@douyinfe/semi-ui'],
  34. 'semantic': ['semantic-ui-css', 'semantic-ui-react'],
  35. 'visactor': ['@visactor/react-vchart', '@visactor/vchart'],
  36. 'tools': ['axios', 'history', 'marked'],
  37. 'react-components': ['react-dropzone', 'react-fireworks', 'react-telegram-login', 'react-toastify', 'react-turnstile'],
  38. },
  39. },
  40. },
  41. },
  42. server: {
  43. proxy: {
  44. '/api': {
  45. target: "http://localhost:3000",
  46. changeOrigin: true,
  47. }
  48. }
  49. }
  50. });