Play Framework and sbt-web plugin for brotli-compressing web assets at build-time using brotli4j bindings.
Rewritten from sbt-gzip sources, thanks to Typesafe/Lightbend. Some parts of code, docs, tests are copy-pasted with no changes.
Add the plugin to project/plugins.sbt:
addSbtPlugin("com.github.dwickern" % "sbt-web-brotli" % "2.0.0")Add brotli to the sbt-web asset pipeline in your build.sbt:
pipelineStages := Seq(brotli)Pipeline stages are only used in the production build. To see the output of your pipeline, run in your sbt shell:
> show webStage
Include and exclude filters can be provided. For example, to only create brotli files for .js files:
brotli / includeFilter := "*.js"Or to exclude all .js files but include any other files:
brotli / excludeFilter := "*.js"The default filters configured like this:
brotli / includeFilter := "*.html" || "*.css" || "*.js"
brotli / excludeFilter := HiddenFileFilter || "*.woff" || "*.woff2" || "*.gz"If you also use sbt-gzip, make sure brotli comes after gzip in the pipeline:
pipelineStages := Seq(gzip, brotli)Or, alternatively, configure gzip to ignore the brotli-compressed files:
pipelineStages := Seq(brotli, gzip)
gzip / excludeFilter ~= { _ || "*.br" }If you encounter java.lang.UnsatisfiedLinkError: Failed to load Brotli native library
- Upgrade to sbt 1.7.3 or later, which includes an important fix coursier#2286
- Make sure you're using a platform supported by brotli4j
- Make sure Couriser is not disabled (e.g. with the
useCoursiersetting)
Otherwise, you can add the brotli4j native library for your platform to libraryDependencies in project/plugins.sbt.
This code is licensed under the Apache 2.0 License.