rules_terser
v2.0.0
published 3 months ago
7 stars
1 forks
3 watchers
Apache License 2.0
public
1 assets
75,890 downloads
30 KB
Compatability level 1
MKvcIcHVOduMkgmxcFu+3EDBtxTQJPpjCWFTP40Iqrg=
Maintained byAspect team
v2.0.0
August 15, 2024

WORKSPACE snippet:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
http_archive(
    name = "aspect_rules_terser",
    sha256 = "30abdc21c1d539db8c9209b1705bbedc40c1b714d024fa630961533f8d08aab8",
    strip_prefix = "rules_terser-2.0.0",
    url = "https://github.com/aspect-build/rules_terser/releases/download/v2.0.0/rules_terser-v2.0.0.tar.gz",
)

######################
# rules_terser setup #
######################

# Fetch the Bazel module dependencies

load("@aspect_rules_terser//terser:dependencies.bzl", "rules_terser_dependencies")

rules_terser_dependencies()

# Fetch and register a nodejs interpreter, if you haven't already

load("@aspect_rules_js//js:toolchains.bzl", "DEFAULT_NODE_VERSION", "rules_js_register_toolchains")

rules_js_register_toolchains(node_version = DEFAULT_NODE_VERSION)

load("@aspect_rules_js//npm:repositories.bzl", "npm_translate_lock")

npm_translate_lock(
    name = "npm",
    npmrc = "//:.npmrc",
    pnpm_lock = "//:pnpm-lock.yaml",
    verify_node_modules_ignored = "//:.bazelignore",
)

load("@npm//:repositories.bzl", "npm_repositories")

npm_repositories()

What's Changed

Full Changelog: https://github.com/aspect-build/rules_terser/compare/v1.0.1...v2.0.0

Deps:
Assets:

Bazel rules for terser

terser is a JavaScript minifier.

These rules teach Bazel how to interact with the terser CLI.

Need help? This ruleset has support provided by https://aspect.dev.

Installation

From the release you wish to use: https://github.com/aspect-build/rules_terser/releases copy the WORKSPACE snippet into your WORKSPACE file.

Usage

See the API documentation and the example usage in the examples/ directory. Note that the examples rely on code in the /WORKSPACE file in the root of this repo.

From a BUILD file

This is the most common usage. See examples/minify

From a macro

You could write a Bazel macro which uses terser, by calling it from a genrule or run_binary. This is illustrated in examples/macro.

From a custom rule

The most advanced usage is to write your own custom rule.

This is a good choice if you need to integrate with other Bazel rules via Providers.