JVM跨项目如何加载javascript

How to load javascript in the JVM cross project

我 运行 遇到了一些困难,想知道是否有人可以帮助我。我有以下 Build.scala,我正在尝试从 JVM 项目访问编译 javascript。

lazy val webProject = CrossProject(base = file("./main/web"), crossType = CrossType.Full, jvmId = "api-gateway", jsId = "web-js")
    .settings(
      name := "web",
      unmanagedSourceDirectories in Compile += baseDirectory.value / "shared" / "main" / "scala",
      libraryDependencies ++= Dependencies.Client.sharedDeps.value)
    .jvmSettings(
      persistLauncher := true,
      persistLauncher in Test := false,
      libraryDependencies ++= Dependencies.Client.jvmDeps.value)
    .jsSettings(libraryDependencies ++= Dependencies.Client.jsDeps.value)

  lazy val webJS = webProject.js.enablePlugins(ScalaJSPlugin)

  lazy val webJVM = webProject.jvm
    .settings((resources in Compile) += (fastOptJS in(webJS, Compile)).value.data)
    .dependsOn(dominos)

编译javascript生成

[info] Fast optimizing /.../main/web/js/target/scala-2.11/web-fastopt.js

当我尝试通过 运行ning get 服务器访问编译 javascript 时,找不到它。

object Main extends App {

  implicit val system = ActorSystem("my-system")
  implicit val materializer = ActorMaterializer()
  implicit val executionContext = system.dispatcher

  val routes = pathEndOrSingleSlash(getFromResource("web-fastopt.js"))

  Http().bindAndHandle(routes, "localhost", 8080)
}

这一行是不是应该在 运行 时将 javascript 添加到 JVM 的资源文件夹中?

(resources in Compile) += (fastOptJS in(webJS, Compile)).value.data

如有任何帮助,我们将不胜感激。

由于某些原因,我觉得这个好像不起作用

(resources in Compile) += (fastOptJS in(webJS, Compile)).value.data

相反,我不再需要移动 fastOptJS 文件

lazy val webJVM = webProject.jvm
    .settings(Seq(fastOptJS, fullOptJS, packageJSDependencies)
      .map(pkg ⇒ crossTarget in(webJS, Compile, pkg) := scalaJSOutput.value))

我还需要添加

getFromResourceDirectory("")

Akka Http 路由。