Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add the output path of JavaScripts from scala.js to Play?

I'm trying to get play (exactly sbt-web) to access the javascript files created from scala.js.

With unmanagedResourceDirectories in Assets += I'm able to set a paht for the sbt-web to automatically copy to the right asset directory. The problem is that I won't hardcode the path to the javascript files.

My Build.scala looks like this:

import play.Play._
import com.typesafe.sbt.web.Import.Assets
import scala.scalajs.sbtplugin.ScalaJSPlugin._
import scala.scalajs.sbtplugin.ScalaJSPlugin.ScalaJSKeys._

object Build extends sbt.Build {
    override def rootProject = Some(jvm) 

    lazy val js = project
                    .settings(scalaJSSettings: _*)
                    .settings(
                       scalaVersion := "2.11.2"
                    )

    lazy val jvm = project
                     .settings(play.PlayScala)
                     .settins(
                       scalaVersion := "2.11.2",
                       // This is the interesting line
                       unmanagedResourceDirectories in Assets += (target in js).value / "scala-2.11",
                       compile in Compile <<= (compile in Compile) dependsOn (fastOptJS in (js, Compile))
                     )
                     .aggregate(js)
}

Is there a way to get the output path of the javascript from scala.js?

(target in js).value / "scala-2.11" works, but there is the hardcoded scala-2.11 and the classes directory in the assets output.

Another Problem is that the files now are under web/public/main/ instead of web/public/main/js.

like image 608
semptic Avatar asked Mar 18 '23 09:03

semptic


1 Answers

Instead of (target in js).value / "scala-2.11", you can use (crossTarget in js).value. It will append the right subdirectory, depending on your Scala version.

The fully qualified name of the file generated by fastOptJS in (js, Compile) is artifactPath in (js, Compile, fastOptJS), as is customary in sbt.

You can also change the destination file of fastOptJS by modifying artifactPath instead. This could help you with your last problem. This technique can be used to send the generated file directly to the managed resources of the jvm project.

like image 61
sjrd Avatar answered Apr 24 '23 00:04

sjrd