npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bazel/terser

v5.8.1

Published

Run Terser JS optimizer under Bazel

Downloads

66,606

Readme

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