vmunier / sbt-web-scalajs

SBT plugin to use Scala.js along with any sbt-web server.
Apache License 2.0
194 stars 30 forks source link

Using the suggested setup requires a full compile in order to "import" SBT project in IntelliJ #169

Closed ryan-richt closed 1 year ago

ryan-richt commented 1 year ago

Does this happen to anyone else? A problem for us for years, and I thought maybe we were doing something wrong. The example here is quite helpful though and seems to be what we are doing.

ryan-richt commented 1 year ago

There are a few historical reports on the Gitter, but I don't think a known solution:

Bob R @tzbob Sep 09 2016 07:06 @vmunier I'm hitting some issues and I'm not sure if it's because of me, intellij or sbt-web-scalajs Say I have code that doesn't compile in a regular sbt build, I import it into intellij and they run their sbt task to import sources and whatnot, everything works. When I do the same thing with an 'sbt-web-scalajs'-enabled project it seems like their tasks are triggering compilation. Before I look into this, has anyone had a similar experience? I can't imagine being the only person who had this issue.

Binh Nguyen @ngbinh Mar 17 2017 04:11 Hey guys, when I switch to sbt-web-sclajs, everytime I refresh SBT in IntelliJ, it compiles the whole code base again. IntelliJ also clashes with my external ./sbt process in the sense that a full IntelliJ refresh will trigger a full recompile in external sbt. So is there a way to not having IntellIJ to compile the main source code on refresh?

ryan-richt commented 1 year ago

For posterity, the offending setting is actually this:

Runtime / managedClasspath += (Assets / packageBin).value

Mentioned by @vmunier long ago on Gitter:

Vincent Munier @vmunier Oct 28 2016 10:14
I think you are referring to using the plugin with Akka HTTP, and thus using this line managedClasspath in Runtime += (packageBin in Assets).value in your config.
It's true that the packageBin operation can take time, but I haven't found another way to include sbt-web assets in an Akka HTTP project.

Long discussion here (unresolved): https://github.com/sbt/sbt/issues/3578

More here (this is the recommendation from sbt-native-packager docs, but has this problem): https://github.com/sbt/sbt-native-packager/issues/699

ryan-richt commented 1 year ago

https://github.com/vmunier/akka-http-scalajs.g8#classpath-during-development

Currently testing this ^^^ as the solution. ~Some suspicion it results in "dirty builds" but still evaluating.~

For posterity:

Replace:

Assets / WebKeys.packagePrefix := "public/",
Runtime / managedClasspath += (Assets / packageBin).value

with

lazy val server = project.settings(
...
Assets / WebKeys.packagePrefix := "public/",
Assets / WebKeys.exportedMappings ++= (for ((file, path) <- (Assets / mappings).value)
  yield file -> ((Assets / WebKeys.packagePrefix).value + path)),
...
)
ryan-richt commented 1 year ago

This ^^ indeed solves the IntelliJ issue. We might consider changing this line below to that recommendation (I dont think it has any side effects other than making it "do what you want" in more situations?), but this issue should probably be closed.

https://github.com/vmunier/sbt-web-scalajs/blob/11a00edfc92a639bceba7432c848ec32eb579949/src/sbt-test/sbt-web-scalajs/akka-http-scalajs/build.sbt#L20