ScalaJS fastOptJS 并使用 sbt-native-packager 启动脚本

ScalaJS fastOptJS and start script with sbt-native-packager

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

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

工作正常 运行 sbt re-startsbt run-main WebServer 现在,使用 sbt-native-pagkager 插件,我想打包所有的东西并为我的项目生成一个启动脚本。

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

有些东西应该对 here 有帮助,但对我来说绝对没有帮助。

顺便说一句,我的 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)

 ....

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

我的错!

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

生成

现在可以正常使用了!!