Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nafg/mill-bundler
Javascript module resolution and bundling for the Mill build tool
https://github.com/nafg/mill-bundler
mill mill-plugin npm rollup scala webpack
Last synced: 1 day ago
JSON representation
Javascript module resolution and bundling for the Mill build tool
- Host: GitHub
- URL: https://github.com/nafg/mill-bundler
- Owner: nafg
- License: apache-2.0
- Created: 2022-11-23T21:52:05.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-01-21T21:49:20.000Z (10 months ago)
- Last Synced: 2024-05-01T19:36:51.494Z (7 months ago)
- Topics: mill, mill-plugin, npm, rollup, scala, webpack
- Language: Scala
- Homepage:
- Size: 50.8 KB
- Stars: 4
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mill-bundler
A Mill plugin for managing NPM dependencies for Scala.js code, and bundling the output.
## Usage
### 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`.
```scala
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() ++
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.### Bundling
To bundle your Scala.js code, mix in `ScalaJSRollupModule` or `ScalaJSWebpackModule` into your module. They extend
ScalaJSNpmModule, so everything from the previous section applies.```scala
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.### Testing
`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.