react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Speed up development on demos by using esbuild and aliases

Open djhi opened this issue 3 years ago • 7 comments

Problem

Working on the e-commerce and crm demos is a pain because of the default CRA config:

  • You have to build the ra packages at least once before running the demos
  • You have to rebuild the ra packages whenever they change
  • You have to restart the demo to actually see the changes
  • The e-commerce demo takes forever to start and load

Solution

For development only, leverage esbuild and aliases using craco. We still use the default CRA config for building.

Benchmarks on Dell XPS 13

Webpack:

  • need to build ra packages at least once and rebuild them each time they change: 1m21
  • first run of the demo: 1m until usable
  • subsequent runs of the demo: 15s

Craco with Esbuild and aliases (dev only):

  • no need to build/rebuild the packages ever
  • first run of the demo: 30s until usable
  • subsequent runs of the demo: 10s

Limitations

While we don't have to build ra packages anymore while working on the demos, I haven't been able to make fast refresh handle the ra packages changes so you still have to refresh the page manually. We didn't have this feature with the default CRA either though so we still get some great benefits.

djhi avatar Jan 29 '22 08:01 djhi

Very good, but a doubt, why not use Vite? same as example/simple ?

lukascivil avatar Jan 30 '22 13:01 lukascivil

I'd love to but we need to keep at least one CRA to ensure their users don't have any issues

djhi avatar Jan 31 '22 08:01 djhi

Also, does it typecheck the demos?

fzaninotto avatar Feb 01 '22 15:02 fzaninotto

At build time, yes. Otherwise, it happens in your editor just like the packages

djhi avatar Feb 01 '22 15:02 djhi

This is pretty cool. @fzaninotto I was thinking of migrating the project to use yarn workspaces + vite (esbuild + rollup), move away from tsup + lerna. This will give us support for tsconfig references + composite builds, and seems faster at compiling deterministically.

This would be ideal, as it'll better allow for developing projects along-side react-admin (as I'm trying to do at the moment).

Also, hi! Future contributor here

antdking avatar Feb 25 '22 14:02 antdking

We already uses yarn workspaces and esbuild (through tsup). Lerna is only used for publishing. We don't want to use only vite as we need a way to validate everything works for CRA users

djhi avatar Feb 25 '22 14:02 djhi

alas, it's not supported yet: https://github.com/egoist/tsup/issues/571

antdking avatar Feb 26 '22 02:02 antdking

Superseded by #8317

WiXSL avatar Oct 27 '22 13:10 WiXSL