Dynamically switch between the JVM and JS targets in an sbt build, as well as between different versions of Scala.js.
Do not use this project if
You want something supported
sbt-dynscalajs was written as a proof of concept. The author does not intend to improve it nor to fix bugs. Therefore, you should expect to fix things yourself.
The author only intends to update it to make it work with newer versions of Scala.js, should they break the proof of concept.
You develop Scala.js-specific things
sbt-dynscalajs only has the most basic features necessary to build, run and test with Scala.js a project mainly intended for the JVM. It does not have features targeted at Scala.js users. Things that are absent include, but are not limited to:
- Support for a
sharedcross-compiling project used by a JVM server and a JS server
crossProject(the plugin replaces that mechanism)
- Support for downstream sbt plugins extending Scala.js (e.g.,
- Support for sbt 0.13.x
Do use this project if
All of the following apply:
- You are prepared to fix bugs and improve the plugin yourself
- You maintain a Scala library and are mostly interested in its JVM flavour
- You want to build, test and publish the Scala.js version of your library
- You do not like
crossProject, and/or you do not like environment variables to switch between Scala.js 0.6.x and 1.x
- Your project uses sbt 1.x
Add the following dependency in your
addSbtPlugin("be.doeraene" % "sbt-dynscalajs" % "0.4.0")
You will also need to enable the
DynScalaJSPlugin auto-plugin on
projects you want to cross-compile, e.g.
lazy val foo = project. enablePlugins(DynScalaJSPlugin). ...
In the future,
DynScalaJSPlugin may become auto-triggered so that this is not necessary, but we stay safe for now.
- Make sure your project uses sbt 1.x, minimum 1.2.1.
- Dependencies on other Scala/Scala.js libraries should use
%%, as if you were using sbt-crossproject.
- If your project has a
mainmethod that you want to
run, make sure to put
scalaJSUseMainModuleInitializer := truein that project's settings.
If you were using sbt-scalajs
You must remove
sbt-scalajs from your project.
sbt-dynscalajs is not compatible with sbt-scalajs, as it completely redefines its API.
Having both on the classpath of your build will break everything.
crossProjects should be replaced by simple
projects enabling the
Once everything is setup, you can start sbt. By default, all your projects are configured for the JVM, as if you had done nothing. All tasks will behave as usual for a JVM project.
To switch to Scala.js, enter:
> set dynScalaJSVersion := Some("1.0.0-RC1")
or another supported version of Scala.js.
Magic! All the projects with
enablePlugins(DynScalaJSPlugin) have been turned into Scala.js projects, using the specified version of Scala.js.
You can now use the most common Scala.js tasks, such as
testQuick) behave as on a Scala.js project.
Supported versions of Scala.js
The current version of sbt-dynscalajs has been tested with:
- Scala.js 0.6.28
- Scala.js 1.0.0-RC1
Later versions in the 0.6.x cycle are expected to be compatible as well.