You need to have
npm installed on your system.
sbt-scalajs-bundler plugin to your Scala.js project, in your
The plugin requires Scala.js 0.6.26+ or 1.0.0-RC1 and either sbt 0.13.17+ or 1.2.1+.
ScalaJSBundlerPlugin, in your
If you have a
main method, make sure that you enable the Scala.js main module initializer with the following setting:
Add dependencies to the npm packages your application requires, in your
build.sbt file, e.g.:
Then, use the
fastOptJS::webpack sbt command to download the npm packages and bundle your Scala.js
In this example, the
webpack sbt task produces a single file located at
See complete examples in the tests.
For sbt-web integration use the
sbt-web-scalajs-bundler plugin instead of
Then, enable the
WebScalaJSBundlerPlugin on the project that uses sbt-web:
You also need to setup the
ScalaJSBundlerPlugin on the Scala.js project, as described in the preceding section, and
sbt-web-scalajs plugins as described in their documentation.
ScalaJSWeb plugin must not be enabled, because
ScalaJSWeb will create source
mappings to source files copied to a hash path, which conflict with
ScalaJSBundlerPlugin's webpack-based source mappings.
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.