vite.config.js 804 B

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