This week we release the first version of scalajs-bundler, a tool that makes it easier to use npm packages for Scala.js developers. This effort is part of the Scala Center’s initiative to ensure the continuity of the Scala.js project.
Our goal is to make npm dependencies management as easy as JVM dependencies management.
Basically, if your application needs to use an npm package
foo, all you have to do is to
add to your build a line like the following:
npmDependencies in Compile += "foo" -> "1.0"
And then the usual
test sbt commands just work.
There are mainly two existing approaches to tackle these challenges: using WebJars or combining two build systems (one for the Scala world and one for the npm world). Both of them require extra efforts from developers or have limitations (you can find more details about that in scalajs-bundler’s documentation).
scalajs-bundler leverages the CommonJS modules support brought by the latest Scala.js release.
The 0.1 release contains an sbt plugin that:
- lets developers define their npm dependencies (as in the introductory example),
- keeps track of transitive npm dependencies between Scala.js artifacts,
- fetches these dependencies from the npm registry,
- provides tasks to bundle the application into a single artifact executable by web browsers.
We also provide a second sbt plugin that integrates with sbt-web-scalajs: it basically turns bundles into sbt-web assets.
There is still some work to do (in particular to shorten the duration of the bundling process in the context of live reloading workflows) and we expect to release a 0.2 version soon, but this first release is already usable, so don’t hesitate to give it a try, we’d love to get your feedback!