lazy val shared = commonSettings ++ Seq(
name := "intranet-shared",
libraryDependencies ++= Dependencies.shared.value,
)
lazy val server = commonSettings ++ Seq(
name := "intranet-server",
libraryDependencies ++= Dependencies.server,
libraryDependencies ++= Dependencies.jvm,
pipelineStages in Assets := Seq(scalaJSPipeline),
compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
WebKeys.packagePrefix in Assets := "public/",
managedClasspath in Runtime += (packageBin in Assets).value,
)
lazy val client = commonSettings ++ Seq(
name := "intranet-client",
mainClass in Compile := Some("app.Application"),
libraryDependencies ++= Dependencies.client.value,
npmDependencies in Compile := Dependencies.js,
npmDevDependencies in Compile := Dependencies.devJs,
webpackConfigFile in fastOptJS := Some(baseDirectory.value / "dev.webpack.config.js"),
webpackConfigFile in fullOptJS := Some(baseDirectory.value / "prod.webpack.config.js"),
scalaJSUseMainModuleInitializer := true,
scalaJSUseMainModuleInitializer in Test := false,
jsEnv := new org.scalajs.jsenv.jsdomnodejs.JSDOMNodeJSEnv,
webpackBundlingMode := BundlingMode.LibraryOnly(),
)
build.sbt
lazy val shared = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
.in(file("shared"))
.settings(BuildSettings.shared)
.jsConfigure(_.enablePlugins(ScalaJSWeb, ScalaJSBundlerPlugin))
lazy val sharedJVM = shared.jvm.settings(name := "sharedJVM")
lazy val sharedJS = shared.js.settings(name := "sharedJS")
lazy val server = project
.in(file("server"))
.settings(BuildSettings.server)
.settings(scalaJSProjects := Seq(client))
.enablePlugins(WebScalaJSBundlerPlugin, SbtTwirl, JavaAppPackaging)
.aggregate(client)
.dependsOn(sharedJVM)
lazy val client: Project = project
.in(file("client"))
.settings(BuildSettings.client)
.enablePlugins(ScalaJSPlugin, ScalaJSBundlerPlugin, ScalaJSWeb)
.dependsOn(sharedJS)
onLoad in Global := (onLoad in Global).value andThen {s: State => "project server" :: s}
http://127.0.0.1:8080/assets/intranet-client-fastopt-library.js
http://127.0.0.1:8080/assets/intranet-client-fastopt-loader.js
http://127.0.0.1:8080/assets/intranet-client-fastopt.js
import java.nio.file.{Files, StandardCopyOption}
import com.typesafe.sbt.packager.SettingsHelper._
lazy val server = project
.in(file("server"))
.settings(BuildSettings.server)
.settings(
scalaJSProjects := Seq(client),
(Compile / resourceGenerators) += Def.task {
val webpackFiles = (client / Compile / fullOptJS / webpack).value.map(_.data).filterNot(_.getName contains "bundle")
val npmFiles = Seq.empty[File]
(webpackFiles ++ npmFiles).map { sourceFile =>
val targetFile = (Compile / resourceManaged).value / "public" / sourceFile.getName
Files.createDirectories(targetFile.getParentFile().toPath())
Files.copy(sourceFile.toPath, targetFile.toPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.COPY_ATTRIBUTES)
targetFile
}
}.taskValue,
)
.enablePlugins(WebScalaJSBundlerPlugin, SbtTwirl, JavaAppPackaging)
.aggregate(client)
.dependsOn(sharedJVM)
show compile:managedResources
[info] client / Compile / managedResources
[info] List()
[info] Compile / managedResources
[info] List(/home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt.js, /home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt-loader.js, /home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt-library.js, /home/user/Projects/intranet/server/target/scala-2.12/resource_managed/main/public/intranet-client-opt-library.js.map)
~run
and ~reStart
but if I change the SharedMessages.itWorks content, and refresh the page, it doesn't show the update message unless I ctrl + c and re-run it.
~reStart
and changing SharedMessages.scala
, I can see in the SBT output that it's calling fastoptjs (Fast optimizing ...
). However, I don't see the Scala.js message being updated in Chrome when I reload the page. I do see the change when I open a private window, so it's probably a caching issue.
Hi, it looks like you need to use triple %, so that scalatest and scalacheck can be used from Scala.js. You will also need to use Scala.js 0.6.x instead of Scala.js 1.x because scalatest & scalacheck are not compatible with Scala.js 1.x yet. So, update your build.sbt to have:
"org.scalatest" %%% "scalatest" % "3.0.5" % Test,
"org.scalacheck" %%% "scalacheck" % "1.14.0" % Test
and update your project/plugins.sbt
to use:
addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.0.8-0.6")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.23")
You should then be able to run your client's tests.
fastOptJS/webpack
WebKeys.public in Assets := file("<folder-path>")
in the server project
I'm trying to build a ScalaJS project with Scala 3. If I run my project with scala 2.13 it works fine, but if I change the version to 3.0.0-M3 it fails with bad option: -P:scalajs:mapSourceURI:...
The issue persists even with the bare minimum configuration:
lazy val client = (project in file("client"))
.settings(commonSettings)
.settings(
scalaVersion := "3.0.0-M3",
scalaJSUseMainModuleInitializer := true
)
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
and plugins:
addSbtPlugin("ch.epfl.lamp" % "sbt-dotty" % "0.5.1")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.3.1")
addSbtPlugin("com.vmunier" % "sbt-web-scalajs" % "1.1.0")
Any clue how to resolve this issue?