Home  >  Q&A  >  body text

The title is rewritten as: "Integrating Server-Side Rendering with scalajs-react" is translated into Chinese as "Integrating scalajs-react with server-side rendering"

<p>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.</p> <p>我正在使用<code>SBT 1.5.5</code>,<code>scala 2.12.10</code>以及以下相关插件:</p> <pre class="brush:php;toolbar:false;">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")</pre> <p>在文章的<strong>第2步</strong>中,它说要将以下内容添加到'build.sbt'文件中:</p> <pre class="brush:php;toolbar:false;">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) )</pre> <p>So I currently have 2 questions here: </p> <ol> <li><p><code>crossProject</code> does not seem to accept <code>String</code> as a parameter, that is: </p> <p><code>def crossProject(Platform: sbtcrossproject.Platform*)</code></p> </li> <li><p>At <code>val task = stageKey(stage)</code> - <code>stageKey</code> 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. </p> </li> </ol></p>
P粉155551728P粉155551728389 days ago486

reply all(1)I'll reply

  • P粉378890106

    P粉3788901062023-08-31 10:11:47

    As @tdimoff already said, the crossProject method of the sbtcrossproject library does not accept string parameters, so this line of code lazy val webappSsr = crossProject(" webapp-ssr") should be replaced with lazy 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.

    reply
    0
  • Cancelreply