An sbt plugin that compiles SCSS to CSS at build time using
dart-sass-embedded (no Node required),
with a custom importer that resolves @import / @use statements against
WebJar JARs on the build classpath.
Supports sbt 1.x and sbt 2.x.
In project/plugins.sbt:
addSbtPlugin("com.jamesward" % "sbt-sass" % "<version>")The plugin auto-enables on every JVM project — no enablePlugins(...) needed.
-
Put SCSS sources in
src/main/scss/:src/main/scss/app.scss -
Add WebJar dependencies scoped to
"sass":libraryDependencies += "org.webjars.npm" % "bootstrap" % "5.3.8" % "sass"
Or, if you also use sbt-webjars:
libraryDependencies += "org.webjars.npm" % "bootstrap" % "5.3.8" % Set(WebJar, Sass, Test)
-
Import from WebJars using the artifact name as the first path segment:
// src/main/scss/app.scss @import "bootstrap/scss/bootstrap";
-
Run
compile— CSS appears at runtime on the classpath underpublic/:target/.../resource_managed/main/public/app.css target/.../resource_managed/main/public/app.css.mapSource maps are emitted with SCSS sources inlined for DevTools.
| Key | Type | Default |
|---|---|---|
Sass |
Configuration |
Hidden Ivy config added by the plugin |
sassSource |
File |
src/main/scss |
sassTarget |
File |
Compile / resourceManaged / "public" |
sassCompile |
Seq[File] |
Task that compiles SCSS → CSS |
sassCompile is wired into Compile / resourceGenerators, so compile,
run, package, etc. all trigger SCSS compilation automatically.
The plugin ships WebJarsScssImporter, which resolves imports using
webjars-locator-core.
For each import it tries the standard SCSS file-resolution order:
_<name>.scss<name>.scss<name>/_index.scss<name>/index.scss
This means @import "bootstrap/scss/functions" resolves to
_functions.scss inside the bootstrap WebJar JAR — just like a
local Sass install would.
./sbt +compile # cross-build for sbt 1.x and 2.x
./sbt scripted # run integration tests
./sbt +publishLocal # install locally for both sbt versions