3

I have run into some difficulties and was wondering if someone can help me. I have the following Build.scala and I am trying to access the the compile javascript from the JVM project.

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)

The compile javascript is generated

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

When I try to access the compile javascript by running get server, it can't be found.

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)
}

Isn't this line suppose to add the javascript the the JVM's resources folder when it runs?

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

Any help would be greatly appreciated.

1 Answer 1

1

Seems like this like doesn't work for me for some reason

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

Instead I ended having to move the fastOptJS file

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

I also needed to add

getFromResourceDirectory("")

to the Akka Http routes.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.