This gist will modify your babel-loader
in place to use esbuild-loader
instead. Also by default webpacker 5 and below compile your node_modules, so it also modifies the loader for that as well.
Esbuild is a super fast javascript transpiler built in Go. It also uses nice language like: targets: es7
so no more fighting with .browserslistrc
It will also auto transform syntax like: static values = {}
Heres a full list of transforms: https://esbuild.github.io/content-types/#javascript
Esbuild Loader: https://github.com/privatenumber/esbuild-loader
Esbuild: https://esbuild.github.io/
yarn install esbuild-loader
Then modify your config/webpacker/environment.js
to look as above.
Thats it! You can now delete your babel.config.js
and your .browserslistrc
and you can simply target an es{x}
version!
We ended up building something that's so simple that it's not even very esbuild-specific. We write a Webpack-like manifest with this esbuild plugin:
Then we replace Webpacker's manifest mapping:
I think you could probably just use the manifest-writing plugin and continue to use Webpacker's asset pack path helpers if you wanted to minimize bespoke code.
This change turned our 8-18 minute deploys to < 3m, and we haven't had a single issue related to esbuild and asset mapping. I'm not ready to support it for others but I'm happy to share what we've used.