vite.config.js 879 B

12345678910111213141516171819202122232425262728293031323334353637383940
  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. server: {
  31. proxy: {
  32. '/api': {
  33. target: "http://localhost:3000",
  34. changeOrigin: true,
  35. }
  36. }
  37. }
  38. });