scalajs-bundler icon indicating copy to clipboard operation
scalajs-bundler copied to clipboard

Vhiairrassary/es modules support

Open jeroentervoorde opened this issue 5 years ago • 5 comments

I updated the previous PR https://github.com/scalacenter/scalajs-bundler/pull/312 against current master. It seems to work fine except for this warning when trying to configure ES modules in fullOptJS ):

"The module kind in scalaJSLinkerConfig in (myProject, compile, fullOptJS) is different than the one in (myProject, compile)`. Some things will go wrong."

In build.sbt I used: scalaJSLinkerConfig in fullOptJS ~= (_.withModuleKind(ModuleKind.ESModule))

Not sure what to do about that. We should be able to configure ES modules in fullOptJS only i guess as it does not work will BundlingMode.LibraryOnly()

My reason to enable this is fullOptJS is the smaller bundler size. It generates a 25% smaller output file. Probably because of the better DCE for ES modules in webpack.

jeroentervoorde avatar Apr 06 '20 18:04 jeroentervoorde

The warning is legitimate, and you should heed it. You'll run into all sorts of issues if you set the module kind in fullOptJS differently from not in fullOptJS (same with in fastOptJS). sbt-scalajs assumes that they are not overridden per task, which is why it emits that warning.

sjrd avatar Apr 06 '20 19:04 sjrd

Thanks. I already assumed you put that warning there for a reason :) This workaround works for me:

sbt "set scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.ESModule))" clean fullOptJS::webpack

If i update the documentation would you / @julienrf be willing to merge this?

jeroentervoorde avatar Apr 07 '20 18:04 jeroentervoorde

I'd like to see this as well, we get a major size reduction with es6 too

dispalt avatar May 15 '20 17:05 dispalt

Actually that is incorrect, I don't get any savings. I must have been mixing something up in my head with 0.6... Sorry for the noise, but fullOpt shouldn't get any savings because of this. https://github.com/scala-js/scala-js/issues/3893

dispalt avatar May 19 '20 21:05 dispalt

Any news on this?

nightscape avatar Jan 03 '21 15:01 nightscape