标题重写为:将"Integrating Server-Side Rendering with scalajs-react"翻译成中文为"将scalajs-react与服务器端渲染集成"
P粉155551728
P粉155551728 2023-08-30 10:58:29
[React讨论组]
<p>我一直在尝试按照scalajs-react中集成服务器端渲染的指南,但我的堆栈可能有些不同,所以不是那么直观。</p> <p>我正在使用<code>SBT 1.5.5</code>,<code>scala 2.12.10</code>以及以下相关插件:</p> <pre class="brush:php;toolbar:false;">addSbtPlugin(&quot;com.typesafe.play&quot; % &quot;sbt-plugin&quot; % &quot;2.7.4&quot;) addSbtPlugin(&quot;org.scala-js&quot; % &quot;sbt-scalajs&quot; % &quot;1.7.0&quot;) addSbtPlugin(&quot;org.scala-js&quot; % &quot;sbt-jsdependencies&quot; % &quot;1.0.2&quot;) addSbtPlugin(&quot;ch.epfl.scala&quot; % &quot;sbt-scalajs-bundler&quot; % &quot;0.20.0&quot;) addSbtPlugin(&quot;com.eed3si9n&quot; % &quot;sbt-buildinfo&quot; % &quot;0.10.0&quot;) addSbtPlugin(&quot;org.scala-native&quot; % &quot;sbt-scala-native&quot; % &quot;0.3.7&quot;) addSbtPlugin(&quot;org.portable-scala&quot; % &quot;sbt-scalajs-crossproject&quot; % &quot;1.2.0&quot;) addSbtPlugin(&quot;org.portable-scala&quot; % &quot;sbt-scala-native-crossproject&quot; % &quot;1.2.0&quot;)</pre> <p>在文章的<strong>第2步</strong>中,它说要将以下内容添加到'build.sbt'文件中:</p> <pre class="brush:php;toolbar:false;">val scalaGraalVer = &quot;1.0.1&quot; lazy val webappSsr = crossProject(&quot;webapp-ssr&quot;) lazy val webappSsrJs = webappSsr.js .dependsOn(myScalaJsWebapp) // 将此处更改为您真正的SJS模块名称 .settings( libraryDependencies ++= Seq( &quot;com.github.japgolly.scala-graal&quot; %%% &quot;core-js&quot; % scalaGraalVer, &quot;com.github.japgolly.scala-graal&quot; %%% &quot;ext-boopickle&quot; % scalaGraalVer ), scalaJSLinkerConfig ~= { _.withSourceMap(false) }, artifactPath in (Compile, fastOptJS) := (crossTarget.value / &quot;webapp-ssr.js&quot;), artifactPath in (Compile, fullOptJS) := (crossTarget.value / &quot;webapp-ssr.js&quot;) ) lazy val webappSsrJvm = webappSsr.jvm .settings( libraryDependencies ++= Seq( &quot;com.github.japgolly.scala-graal&quot; %% &quot;core&quot; % scalaGraalVer, &quot;com.github.japgolly.scala-graal&quot; %% &quot;core-js&quot; % scalaGraalVer, &quot;com.github.japgolly.scala-graal&quot; %% &quot;ext-boopickle&quot; % 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>所以我目前在这里有2个问题:</p> <ol> <li><p><code>crossProject</code>似乎不接受<code>String</code>作为参数,即:</p> <p><code>def crossProject(平台:sbtcrossproject.Platform*)</code></p> </li> <li><p>在<code>val task = stageKey(stage)</code>处 - <code>stageKey</code>不是一个被识别的函数。我在网上搜索过,但无法弄清楚它的位置,因此不知道我缺少什么或是否有其他方法。</p> </li> </ol></p>
P粉155551728
P粉155551728

全部回复(1)
P粉378890106

就像@tdimoff已经说过的那样,sbtcrossproject库的crossProject方法不接受字符串参数,所以这行代码lazy val webappSsr = crossProject("webapp-ssr")应该替换为lazy val webappSsr = crossProject(JSPlatform, JVMPlatform)

关于stageKey函数,它似乎是scalajs-bundler库的一部分,所以您需要添加以下库依赖:

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

这样应该可以使用stageKey函数。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号