5.8.1 • Published 1 year ago

@bazel/terser v5.8.1

Weekly downloads
20,163
License
Apache-2.0
Repository
github
Last release
1 year ago

Terser rules for Bazel

The Terser rules run the Terser JS minifier with Bazel.

Wraps the Terser CLI documented at https://github.com/terser-js/terser#command-line-usage

Installation

Add the @bazel/terser npm package to your devDependencies in package.json.

Installing with user-managed dependencies

If you didn't use the yarn_install or npm_install rule, you'll have to declare a rule in your root BUILD.bazel file to execute terser:

# Create a terser rule to use in terser_minified#terser_bin
# attribute when using user-managed dependencies
nodejs_binary(
    name = "terser_bin",
    entry_point = "//:node_modules/terser/bin/uglifyjs",
    # Point bazel to your node_modules to find the entry point
    data = ["//:node_modules"],
)

terser_minified

USAGE

Run the terser minifier.

Typical example:

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

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 out.min.js.map (since sourcemap defaults to true). If the input is a directory, then the output will also be a directory, named after the name attribute. Note that this rule is NOT recursive. It assumes a flat file structure. Passing in a folder with nested folder will result in an empty output directory.

ATTRIBUTES

(Name, mandatory): A unique name for this target.

(List of strings): 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 https://github.com/terser/terser#command-line-usage for the full list of terser CLI options.

Defaults to []

(Label): A JSON file containing Terser minify() options.

This is the file you would pass to the --config-file argument in terser's CLI. https://github.com/terser-js/terser#minify-options 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.

Defaults to @npm//@bazel/terser:terser_config.default.json

(Boolean): 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.

Defaults to False

(Boolean): Whether to produce a .js.map output

Defaults to True

(Label, mandatory): 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.

(Label): An executable target that runs Terser

Defaults to @npm//@bazel/terser/bin:terser

5.8.1

1 year ago

5.7.3

1 year ago

5.7.2

1 year ago

5.7.1

1 year ago

5.6.0

2 years ago

5.7.0

1 year ago

5.5.4

2 years ago

5.5.1

2 years ago

5.5.3

2 years ago

5.5.2

2 years ago

5.5.0

2 years ago

5.4.2

2 years ago

5.4.1

2 years ago

5.3.1

2 years ago

5.3.0

2 years ago

5.4.0

2 years ago

5.2.0

2 years ago

5.1.0

2 years ago

5.0.0-rc.0

2 years ago

5.0.0-rc.2

2 years ago

4.6.1

2 years ago

4.6.0

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.6.2

2 years ago

4.5.0

2 years ago

4.4.5

2 years ago

4.4.6

2 years ago

4.4.2

2 years ago

4.4.0

2 years ago

4.3.0

3 years ago

4.2.0

3 years ago

4.1.0

3 years ago

4.0.0

3 years ago

4.0.0-rc.1

3 years ago

3.8.0

3 years ago

4.0.0-rc.0

3 years ago

4.0.0-beta.1

3 years ago

3.7.0

3 years ago

4.0.0-beta.0

3 years ago

3.6.0

3 years ago

3.5.1

3 years ago

3.4.2

3 years ago

3.4.1

3 years ago

3.5.0

3 years ago

3.4.0

3 years ago

3.3.0

3 years ago

3.2.3

3 years ago

3.2.2

3 years ago

3.2.1

3 years ago

3.2.0

3 years ago

3.1.0

3 years ago

2.3.3

3 years ago

3.0.0

3 years ago

2.3.2

3 years ago

3.0.0-rc.1

3 years ago

3.0.0-rc.0

3 years ago

2.3.1

3 years ago

2.3.0

3 years ago

2.2.2

3 years ago

2.2.1

3 years ago

2.2.0

4 years ago

2.1.0

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

2.0.0-rc.3

4 years ago

2.0.0-rc.2

4 years ago

2.0.0-rc.1

4 years ago

2.0.0-rc.0

4 years ago

1.7.0

4 years ago

1.6.1

4 years ago

1.6.0

4 years ago

1.5.0

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.4

4 years ago

1.2.3

4 years ago

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.42.3

4 years ago

0.0.0

4 years ago

0.42.2

4 years ago

0.42.1

4 years ago

0.42.0

4 years ago

0.41.0

4 years ago

0.40.0

4 years ago

0.39.1

4 years ago

0.39.0

4 years ago

0.38.3

4 years ago

0.38.2

4 years ago

0.38.1

4 years ago

0.38.0

5 years ago