vmunier/sbt-web-scalajs

Client source files are included in the distribution

ochrons opened this issue · 6 comments

When using Play 2.4 and sbt-play-scalajs v0.2.6, the Scala sources of the client end up being included in the distribution assets JAR. This didn't happen in earlier version of Play.

ochrons/scalajs-spa-tutorial#20

@vmunier @ochrons
I can't confirm that this is fixed.
I can still find the source in the jar, generated by "publish-local".

I've got the following behaviour:
0.2.5 => no source files
0.2.6 => sourcecode can be found at "/META-INF/resources/webjars/artifactname/version/"
0.2.7 => sourcecode can be found at "/"

Do i miss something? Is this on purpose?

Hi @FlorianKirmaier,

You are right:
0.2.5 => no source files but it's compatible with Play 2.3.x only (the live reloading on Play run does not work when using Play 2.4.x)

0.2.6 => Fixes the live reloading.
Compared to Play 2.3, Play 2.4 is watching different directories to know when to recompile and reload the app:
https://github.com/playframework/playframework/blob/c75ed44baf4433f6b56ec5fdc30993405e8ad178/framework/src/sbt-plugin/src/main/scala/play/sbt/PlayCommands.scala#L85
You can see that Play 2.4 watches unmanagedSourceDirectories and unmanagedResourceDirectories in Compile, Assets and in the play project's dependencies.
We don't want a Play project to depend on a Scala.js project. So sbt-play-scalajs 0.2.6 adds the listed Scala.js projects to unmanagedSourceDirectories in Assets.
It fixed the live reloading but it also put the Scala files from the Scala.js projects into the final jar and they could be requested over http because they were part of the Assets...

0.2.7 => sbt-play-scalajs 0.2.7 adds the listed Scala.js projects to unmanagedResourceDirectories in Compile instead.
So the Scala.js scala files are not accessible over http anymore in prod but they are still present in the jar along with the other resources such as application.conf, routes etc.

To recap, the Scala files are still present in the jar when using sbt-play-scalajs 0.2.7.
They are not accessible over http anymore unless you specify (emitSourceMaps in fullOptJS) := true in the Scala.js projects of your choice, in which case the Scala.js scala files are copied over to the public Assets.
It would be good to have no Scala files at all in the final jar by default, I don't know how to do it for now.

Hi @FlorianKirmaier, @ochrons,

I have just published sbt-play-scalajs v0.2.8 that should fix this issue.

It uses excludeFilter to prevent SbtWeb from adding any descendant files from the Scala.js directories into the packaged jar. Note that you can still use emitSourceMaps in fullOptJS := true in a Scala.js project if you want to have source maps in production. In that case, the Scala files from this project will be copied to the jar.

In this new version, sourceMapsBase and sourceMapsDirectories have been deprecated as they are not used by the plugin anymore, you can safely remove them from your build.
It's now looking at unmanagedSourceDirectories in all the transitive dependencies of the Scala.js projects to find the Scala files to copy to the packaged jar.

You can follow this short commit from play-with-scalajs-example to see how to upgrade to sbt-play-scalajs v0.2.8.

Please let me know if you find any issue.

Thanks,
Vincent

@vmunier
At first impression it looks good!
I couldn't find any sources.
Thank you for the update!

Thanks, I'll update SPA tutorial with a new version!

Cool, thank you all!