addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.4") addSbtPlugin(“org.scala-js” % “sbt-scalajs” % “1.7.0”) addSbtPlugin(“org.scala-js” % “sbt-jsdependency” % “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”)<p>在文章的<strong>第2步</strong>中,它表示只需將以以下內容添加到'build.sbt'文件中:</p>
val scalaGraalVer = "1.0.1"; 惰性 val webappSsr = crossProject(“webapp-ssr”) 惰性 val webappSsrJs = webappSsr.js .dependsOn(myScalaJsWebapp) // 將此處更改為您真正的SJS模組名稱 .設定( 庫依賴關係 = Seq( “com.github.japgolly.scala-graal” %%%“核心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>所以我目前在這裡有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粉3788901062023-08-31 10:11:47
就像@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
函數。