2

我正在使用交叉构建方法开发带有 Scalatags... 的经典 ScalaJS 应用程序:

<root folder>
- client
- project
- server
- shared
- build.sbt

它运行良好,sbt re-start或者sbt run-main WebServer 现在,使用sbt-native-pagkager插件我想打包所有东西并为我的项目生成一个启动脚本。

启动脚本生成有效,但似乎不包括 ScalaJS fastOptJs。

这里有些东西应该有所帮助,但在我的情况下绝对没有。

顺便说一句,我的build.sbt文件看起来像:

val scalaV = "2.12.2"

lazy val server = (project in file("server"))
  .settings(
    scalaVersion := scalaV,
    scalaJSProjects := Seq(client),
    pipelineStages in Assets := Seq(scalaJSPipeline),
    // triggers scalaJSPipeline when using compile or continuous compilation
    compile in Compile := ((compile in Compile) dependsOn scalaJSPipeline).value,
    libraryDependencies ++= Seq(
      ...
    ),

    WebKeys.packagePrefix in Assets := "public/",
    (managedClasspath in Runtime) += (packageBin in Assets).value,
    // Packaging
    topLevelDirectory := None // Don't add a root folder to the archive
  )
  .enablePlugins(SbtWeb, JavaAppPackaging)
  .dependsOn(sharedJvm)

lazy val client = (project in file("client"))
  .settings(
    scalaVersion := scalaV,
    scalaJSUseMainModuleInitializer := true,
    unmanagedSourceDirectories in Compile := Seq((scalaSource in Compile).value),
   libraryDependencies ++= Seq(
     ...
   ),
  jsDependencies ++= Seq(
     ...
  )
)
.enablePlugins(ScalaJSPlugin, ScalaJSWeb)
.dependsOn(sharedJs)

lazy val shared = (crossProject.crossType(CrossType.Pure) in file("shared"))
  .enablePlugins(BuildInfoPlugin)
  .settings(
     scalaVersion := scalaV,
     libraryDependencies ++= Seq(
        ...
     ),
     // build info
    buildInfoOptions += BuildInfoOption.BuildTime,
    buildInfoKeys := Seq[BuildInfoKey](
    ),
    buildInfoPackage := "com.example.build"
  )
  .jsSettings(
     libraryDependencies ++= Seq(
      ...
     )
  )
 .jsConfigure(_ enablePlugins ScalaJSWeb)

 ....

有什么帮助吗?非常感谢!

4

1 回答 1

0

我的错!

我没有在我的 html 模板中引用使用生成的正确 javascript 文件(client-jsdeps.min.js 和 client-opt.js)stage

现在工作正常!!

于 2017-05-30T21:33:03.833 回答