4

I've been trying to follow the guide of integrating server-side rendering in scalajs-react but my stack must be a little different so it's not so super straight-forward.

I'm using SBT 1.5.5, scala 2.12.10 with the following relevant plugins:

  addSbtPlugin("com.typesafe.play"  % "sbt-plugin"                    % "2.7.4")
  addSbtPlugin("org.scala-js"       % "sbt-scalajs"                   % "1.7.0")
  addSbtPlugin("org.scala-js"       % "sbt-jsdependencies"            % "1.0.2")
  addSbtPlugin("ch.epfl.scala"      % "sbt-scalajs-bundler"           % "0.20.0")
  addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.10.0")
  addSbtPlugin("org.scala-native"   % "sbt-scala-native"              % "0.3.7")
  addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject"      % "1.2.0")
  addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")

In Step 2 of the article it says to implement the following into the 'build.sbt' file:

  val scalaGraalVer = "1.0.1"

  lazy val webappSsr = crossProject("webapp-ssr")

  lazy val webappSsrJs = webappSsr.js
    .dependsOn(myScalaJsWebapp) // change this to your real SJS module name(s)
    .settings(
      libraryDependencies ++= Seq(
        "com.github.japgolly.scala-graal" %%% "core-js"       % scalaGraalVer,
        "com.github.japgolly.scala-graal" %%% "ext-boopickle" % scalaGraalVer
      ),
      scalaJSLinkerConfig ~= { _.withSourceMap(false) },
      artifactPath in (Compile, fastOptJS) := (crossTarget.value / "webapp-ssr.js"),
      artifactPath in (Compile, fullOptJS) := (crossTarget.value / "webapp-ssr.js")
    )

  lazy val webappSsrJvm = webappSsr.jvm
    .settings(
      libraryDependencies ++= Seq(
        "com.github.japgolly.scala-graal" %% "core"          % scalaGraalVer,
        "com.github.japgolly.scala-graal" %% "core-js"       % scalaGraalVer,
        "com.github.japgolly.scala-graal" %% "ext-boopickle" % scalaGraalVer
      ),
      unmanagedResources in Compile += Def.taskDyn {
        val stage = (scalaJSStage in Compile in webappSsrJs).value
        val task = stageKey(stage)
        Def.task((task in Compile in webappSsrJs).value.data)
      }.value)
    )

So I currently have 2 issues here:

  1. crossProject does not appear to take a String as a parameter, i.e,

    def crossProject(platforms : sbtcrossproject.Platform*)

  2. Where it says val task = stageKey(stage) - stageKey is not a recognised function. I've searched online but can't fathom where it is located and therefore what I'm lacking or if there is a way around.

  • 1
    Instead of passing a string to `crossProject`, you would define two separate projects, one for the JS and one for the JVM. – tdimoff Jan 20 '23 at 17:55
  • @tdimoff Take half a bow - thank-you. Any ideas on the `stagekey` stuff? – jesus g_force Harris Jan 22 '23 at 10:44
  • @jesusg_forceHarris did you get a working version of this project. – Barry Mar 26 '23 at 11:57
  • @Barry - No I've had to leave this for the time being. Ideally the author (David Barri) would lend some assistance but he's MIA. If I do discover anything - I will post though. Please do likewise.. we have to look out for each other out there – jesus g_force Harris Mar 28 '23 at 09:11

1 Answers1

0

As @tdimoff already said the crossProject method of the sbtcrossproject library does not accept a string parameter, so the line lazy val webappSsr = crossProject("webapp-ssr") should be replaced with lazy val webappSsr = crossProject(JSPlatform, JVMPlatform).

Regarding the stageKey function, it looks like it is part of the scalajs-bundler library, so you will need to add the following library dependency:

libraryDependencies += "ch.epfl.scala" % "scalajs-bundler" % "0.20.0"

This should make the stageKey function available.

sm3sher
  • 2,764
  • 1
  • 11
  • 23
  • Thanks. You'll see from my original question that I added the `scalajs-bundler` in the `plugins.sbt` file but as per your suggestion I also added it in the `build.sbt` file but without success unfortunately – jesus g_force Harris Jan 31 '23 at 10:44