nafg / mill-bundler   0.1.0

Apache License 2.0 GitHub

Javascript module resolution and bundling for the Mill build tool

Scala versions: 2.13
Mill plugins: 0.10


A Mill plugin for managing NPM dependencies for Scala.js code, and bundling the output.


Managing NPM dependencies

To manage NPM dependencies, mix ScalaJSNpmModule into your Mill module.

If you have a dependency on a published library that defines scalajs-bundler's npmDependencies, or otherwise contains an NPM_DEPENDENCIES manifest file in its jar, those NPM dependencies will be automatically added. You can also override the jsDeps target.

You can see the result by running mill frontend.allJsDeps.

import $ivy.`io.github.nafg.millbundler::jsdeps::0.1.0`, io.github.nafg.millbundler.jsdeps._

object frontend extends ScalaJSNpmModule {
  override def scalaVersion = "2.13.10"
  override def scalaJSVersion = "1.12.0"
  override def jsDeps =
    super.jsDeps() ++
        dependencies = Map(
          "react" -> "17.0.2",
          "react-dom" -> "^17"
        devDependencies = Map(
          "typescript" -> "*"
        jsSources = Map(
          "demo.js" -> "console.log('hello world')"

The trait provides an npmInstall target, which will run npm install in the directory specified by the jsDepsDir target, which defaults to the one allocated for it by Mill.


To bundle your Scala.js code, mix in ScalaJSRollupModule or ScalaJSWebpackModule into your module. They extend ScalaJSNpmModule, so everything from the previous section applies.

import $ivy.`io.github.nafg.millbundler::millbundler::0.1.0`, io.github.nafg.millbundler._

object frontend extends ScalaJSRollupModule {
  // ...

You can then run mill frontend.devBundle or mill frontend.prodBundle to bundle your Scala.js code into a single JavaScript file.


ScalaJSNpmModule, ScalaJSRollupModule, ScalaJSWebpackModule provide a Test trait in their respective companion objects. You can mix it into your test module to make sure your tests run after the NPM dependencies are installed, and after the bundle is built.