Getting started

Basic setup

You need to have npm installed on your system.

Add the sbt-scalajs-bundler plugin to your Scala.js project, in your project/plugins.sbt file:

addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.14.0")

Note that the plugin requires Scala.js 0.6.22+ and either sbt 0.13.17+ or 1.0.2+.

Enable the ScalaJSBundlerPlugin, in your build.sbt file:


If you have a main method, make sure that you enable the Scala.js main module initializer with the following setting:

scalaJSUseMainModuleInitializer := true

Add dependencies to the npm packages your application requires, in your build.sbt file, e.g.:

npmDependencies in Compile += "snabbdom" -> "0.5.3"

You will most probably want to write a Scala.js facade for your module. You can find information on how to do that in the cookbook, or draw inspiration from this example.

Then, use the fastOptJS::webpack sbt command to download the npm packages and bundle your Scala.js application into a JavaScript file executable by a web browser.

See complete examples in the tests.

Integrating with sbt-web

For sbt-web integration use the sbt-web-scalajs-bundler plugin instead of sbt-scalajs-bundler:

addSbtPlugin("ch.epfl.scala" % "sbt-web-scalajs-bundler" % "0.14.0")

Then, enable the WebScalaJSBundlerPlugin on the project that uses sbt-web:

lazy val server = project
    scalaJSProjects := Seq(client),
    pipelineStages in Assets := Seq(scalaJSPipeline)

lazy val client = project.enablePlugins(ScalaJSBundlerPlugin, ScalaJSWeb)

You also need to setup the ScalaJSBundlerPlugin on the Scala.js project, as described in the preceding section, and the sbt-web-scalajs plugins as described in their documentation.

The WebScalaJSBundlerPlugin plugin automatically configures the scalaJSPipeline task to use the bundles rather than the output of the Scala.js compilation.

You can see a complete example here.