Home

Awesome

sbt-terser

Build Status Apache License V.2

An sbt-web plugin to perform terser optimization on the asset pipeline.

Why choose terser?

uglify-es is no longer maintained and uglify-js does not support ES6+.

terser is a fork of uglify-es that mostly retains API and CLI compatibility with uglify-es and uglify-js@3.

Usage

To use this plugin, use the addSbtPlugin command within your project's plugins.sbt file:

addSbtPlugin("com.github.andriimartynov" % "sbt-terser" % "0.0.1")

Your project's build file also needs to enable sbt-web plugins. For example, with build.sbt:

lazy val root = (project in file(".")).enablePlugins(SbtWeb)

As with all sbt-web asset pipeline plugins you must declare their order of execution:

pipelineStages := Seq(terser)

A standard build profile for the terser optimizer is provided which will mangle variables for obfuscation and compression. Each input .js file found in your assets folders will have a corresponding .min.js file and source maps will also be generated.

includeFilter

If you wish to limit or extend what is uglified then you can use filters:

includeFilter in terser := GlobFilter("myjs/*.js"),

...where the above will include only those files under the myjs folder.

The sbt excludeFilter is also available to the terser scope and defaults to excluding the public folder and extracted Webjars.

Settings

You are able to use and/or customize settings already made, and add your own. Here are a list of relevant settings and their meanings (please refer to the terser documentation for details on the options):

OptionDescriptionDefault
terserBeautifyOptionsSpecify output options.None
terserCommentsPreserve copyright comments in the output.None
terserCompressEnable compressor.false
terserCompressOptionsEnable compressor/specify compressor options.None
terserConfigFileRead minify() options from JSON file.None
terserDefinitionsOptionsGlobal definitions.None
terserEcmaSpecify ECMAScript release.None
terserIE8Support non-standard Internet Explorer 8.false
terserKeepClassNamesDo not mangle/drop class names.false
terserKeepFNamesDo not mangle/drop function names.false
terserMangleMangle names.false
terserMangleOptionsMangle names/specify mangler options.None
terserManglePropsMangle properties/specify mangler options.None
terserModuleInput is an ES6 module.false
terserNameCacheFileFile to hold mangled name mappings.None
terserSafari10Support non-standard Safari 10/11.false
terserTimingsDisplay operations run time on STDERR.false
terserToplevelCompress and/or mangle variables in top level scope.false
terserVerbosePrint diagnostic messages.false
terserWarnPrint warning messages.true
terserWrapEmbed everything in a big function, making the “exports” and “global” variables available.None

The plugin is built on top of JavaScript Engine which supports different JavaScript runtimes.