Public API for terser rules



Run the terser minifier.

Typical example:

load("@npm//@bazel/terser:index.bzl", "terser_minified")

    name = "out.min",
    src = "input.js",
    config_file = "terser_config.json",

Note that the name attribute determines what the resulting files will be called. So the example above will output out.min.js and (since sourcemap defaults to true). If the input is a directory, then the output will also be a directory, named after the name attribute.


A unique name for this target.


Additional command line arguments to pass to terser.

Terser only parses minify() args from the config file so additional arguments such as --comments may be passed to the rule using this attribute. See for the full list of terser CLI options.


A JSON file containing Terser minify() options.

This is the file you would pass to the --config-file argument in terser's CLI. documents the content of the file.

Bazel will make a copy of your config file, treating it as a template.

Run bazel with --subcommands to see the path to the copied file.

If you use the magic strings "bazel_debug" or "bazel_no_debug", these will be replaced with true and false respecting the value of the debug attribute or the --compilation_mode=dbg bazel flag.

For example

    "compress": {
        "arrows": "bazel_no_debug"

Will disable the arrows compression setting when debugging.

If config_file isn't supplied, Bazel will use a default config file.


Configure terser to produce more readable output.

Instead of setting this attribute, consider using debugging compilation mode instead bazel build --compilation_mode=dbg //my/terser:target so that it only affects the current build.


Whether to produce a output


File(s) to minify.

Can be a .js file, a rule producing .js files as its default output, or a rule producing a directory of .js files.

Note that you can pass multiple files to terser, which it will bundle together. If you want to do this, you can pass a filegroup here.


An executable target that runs Terser