vite.config.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import { defineConfig, transformWithEsbuild } from 'vite';
  2. import react from '@vitejs/plugin-react';
  3. import { splitVendorChunkPlugin } from 'vite'
  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 (!id.match(/src\/.*\.js$/)) return null
  11. // Use the exposed transform from vite, instead of directly
  12. // transforming with esbuild
  13. return transformWithEsbuild(code, id, {
  14. loader: 'jsx',
  15. jsx: 'automatic',
  16. })
  17. },
  18. },
  19. react(),
  20. splitVendorChunkPlugin()
  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-vendor': ['react', 'react-dom'],
  35. 'semi': ['@douyinfe/semi-ui'],
  36. 'icons': ['@douyinfe/semi-icons'],
  37. 'semantic': ['semantic-ui-react'],
  38. 'visactor': ['@visactor/react-vchart', '@visactor/vchart']
  39. },
  40. },
  41. },
  42. },
  43. server: {
  44. proxy: {
  45. '/api': {
  46. target: "http://localhost:3000",
  47. changeOrigin: true,
  48. }
  49. }
  50. }
  51. });