scalacenter / scalajs-bundler

https://scalacenter.github.io/scalajs-bundler
Other
236 stars 101 forks source link

esbuild bundler instead of webpack #359

Open ngbinh opened 4 years ago

ngbinh commented 4 years ago

I switched to use esbuild, an extremely fast JS bundler, instead of webpack recently on our big scala.js repo at work. The result is quite impressive, there are projects that esbuild can bundle in seconds where webpack would just OOM.

I still need to rely on scalajs-bundler to pull in npm dependencies. While I can just use scalajs-bundler without webpack by not calling fastOptJS/fullOptJS, I believe it may be beneficial for scala.js ecosystem as a whole to have an official backend on esbuild in scalajs-bundler.

I can try to give this a shot if you guys think it is the right thing for scalajs-bundler

ngbinh commented 4 years ago

just FYI, I have been using esbuild for a couple of months on both production and dev build on a very large scala.js project at work. The plugin is fairly simple, I still need scalajs bundler to pull npm dependencies but not webpack.

julienrf commented 4 years ago

Interesting! Do we need to provide some sort of integration (ie, we would replace the bundling part currently done by webpack with something that uses esbuild)? Or should we remove the concern of bundling from sbt-scalajs-bundler and focus only on fetching NPM dependencies?

ngbinh commented 4 years ago

There are tasks that webpack is better due to its rich ecosystem. But esbuild kills it on js bundling. So I think it would be nice if this plugin provides a clean solution to fetch NPM dependencies. For bundling, because esbuild can handle the whole hundred of MBs js output, you don't need something like LibOnly mode likes in webpack for it to work. It would make the plugin much simpler and there is no need for the bundler to know anything about scalajs internal

cquiroz commented 4 years ago

It maybe interesting to explore this approach. scalajs-bundler approach is nice as you only need sbt running but keeping up to date with the js tooling world takes some effort.

ramnivas commented 4 years ago

Given that module splitting support has landed in 1.3, I don't think we need the libraryOnly mode. So I think "pull npm dependencies only" might be the right role for scalajs-bundler.

cquiroz commented 4 years ago

I wonder the impact of tests. Could we be able to write tests in sbt if there is no bundler integration. I mean tests that would use a facade

He-Pin commented 4 years ago

esbuild is used by Snowpack too

mkotsbak commented 3 years ago

Also consider https://vitejs.dev/, which uses esbuild, as alternative to Webpack.

evbo commented 2 years ago

@ngbinh I agree with @mkotsbak why not consider adopting vite instead of just esbuild?

vite would give a double benefit of bringing the speed of esbuild but also enabling code-splitting (not yet supported in esbuild as I understand...), which is another hot feature: https://github.com/scalacenter/scalajs-bundler/issues/2

So maybe we get 2 birds with 1 stone adopting vite alternative to webpack?

ngbinh commented 2 years ago

Vitejs is great. But if you only need a bundler then using esbuild directly is simpler

matthughes commented 2 years ago

Given that module splitting support has landed in 1.3, I don't think we need the libraryOnly mode. So I think "pull npm dependencies only" might be the right role for scalajs-bundler.

I don't understand this comment. libraryOnly mode is still useful IMO as it allows clients to cache your library's bundles which will change much less frequently than your application code. Or do I misunderstand your point?