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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With