I\'m trying to use scalajs to just compile some scala sources to javascript and not modify anything else about the sbt environment, I don\'t want it to override the default
You must not do this. As soon as you put the scalaJSSettings
in a project, all the sources will be compiled with the Scala.js compiler plugin.
This will indeed produce .class files, however, they contain things the basic Scala compiler does not emit and can therefore lead to binary incompatibility issues or unexpected behavior (see this post).
Instead, use a multi-project build:
import ScalaJSKeys._
organization := "com.example"
scalaVersion := "2.11.4"
val sprayVersion = "1.3.2"
val akkaVersion = "2.3.7"
lazy val foo = project.
settings(
name := "foo",
compile <<= (compile in Compile) dependsOn (fastOptJS in Compile in bar),
crossTarget in (fastOptJS in Compile in bar) :=
((classDirectory in Compile).value / "public" / "js"),
libraryDependencies ++= Seq(
"io.spray" %% "spray-can" % sprayVersion,
"io.spray" %% "spray-routing" % sprayVersion,
"io.spray" %% "spray-servlet" % sprayVersion,
"io.spray" %% "spray-testkit" % sprayVersion % "test",
"com.typesafe.akka" %% "akka-actor" % akkaVersion,
"com.typesafe.akka" %% "akka-testkit" % akkaVersion % "test",
"org.specs2" %% "specs2-core" % "2.3.11" % "test",
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
)
)
lazy val bar = project.
settings(scalaJSSettings: _*).
settings(
name := "bar",
libraryDependencies += "org.scala-lang.modules.scalajs" %%% "scalajs-jquery" % "0.6",
)
This obviously also resolves the issue with the run
command.