This is a Bazel rule which wraps the esbuild CLI.
Features:
@bazel/esbuild
package, so it's easy to migrate.npm install
.Need help? This ruleset has support provided by https://aspect.dev.
From the release you wish to use:
https://github.com/aspect-build/rules_esbuild/releases
copy the WORKSPACE snippet into your WORKSPACE
file.
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.
The simplest usage is with the esbuild
macro.
If needed, instead of the macro you could call the underlying esbuild_bundle
rule directly.
You could write a Bazel macro which uses esbuild, by calling it from a genrule
or
run_binary
.
For this purpose, you can use the ESBUILD_BIN
Make variable exposed by the
@aspect_rules_esbuild//esbuild:resolved_toolchain
.
This is illustrated in examples/macro.
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.
You can follow the example of /esbuild/defs.bzl
by re-using the lib
starlark struct exposed by
/esbuild/private/esbuild.bzl
.
Note that this is a private API which can change without notice.
You can register your own toolchain to provide an esbuild binary. For example, you could build esbuild from source within the Bazel build, so that you can freely edit or patch esbuild and have those changes immediately reflected. You'll need these things:
go_binary
rule.esbuild_toolchain
rule which depends on that binary from step 1 as the target_tool
.toolchain
rule which depends on
that target from step 2 as its toolchain
and
@aspect_rules_esbuild//esbuild:toolchain_type
as its toolchain_type
.register_toolchains
function
in your WORKSPACE
that refers to the toolchain
rule defined in step 3.