I've been trying to follow the guide for integrating server-side rendering in scalajs-react, but my stack may be a little different, so it's not that intuitive.
我正在使用SBT 1.5.5
,scala 2.12.10
以及以下相关插件:
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")
在文章的第2步中,它说要将以下内容添加到'build.sbt'文件中:
val scalaGraalVer = "1.0.1" lazy val webappSsr = crossProject("webapp-ssr") lazy val webappSsrJs = webappSsr.js .dependsOn(myScalaJsWebapp) // 将此处更改为您真正的SJS模块名称 .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 questions here:
crossProject
does not seem to accept String
as a parameter, that is:
def crossProject(Platform: sbtcrossproject.Platform*)
At val task = stageKey(stage)
- stageKey
is not a recognized function. I've searched online but can't figure out where it is so don't know what I'm missing or if there's another way.
As@tdimoffalready said, the
crossProject
method of the sbtcrossproject library does not accept string parameters, so this line of codelazy val webappSsr = crossProject(" webapp-ssr")
should be replaced withlazy val webappSsr = crossProject(JSPlatform, JVMPlatform)
.Regarding the
stageKey
function, it seems to be part of the scalajs-bundler library, so you need to add the following library dependency:libraryDependencies = "ch.epfl.scala" % "scalajs-bundler" % "0.20.0"
This should allow you to use the
stageKey
function.