Skip to main content
Version: 0.14.x

esbuild rule

Rules

esbuild_bundle

Runs the esbuild bundler under Bazel

For further information about esbuild, see https://esbuild.github.io/

Example usage (generated):

load("@aspect_rules_esbuild//esbuild/private:esbuild.bzl", "esbuild_bundle")

esbuild_bundle(
# A unique name for this target.
name = "",
)

name

Required name.

A unique name for this target.

args_file

Optional label. Default: None

Internal use only

config

Optional label. Default: None

Configuration file used for esbuild. Note that options set in this file may get overwritten. TODO: show how to write a config file that depends on plugins, similar to the esbuild_config macro in rules_nodejs.

data

Optional list of labels. Default: []

Runtime dependencies to include in binaries/tests that depend on this target.

The transitive npm dependencies, transitive sources, default outputs and runfiles of targets in the data attribute are added to the runfiles of this target. They should appear in the '*.runfiles' area of any executable which has a runtime dependency on this target.

If this list contains linked npm packages, npm package store targets or other targets that provide JsInfo, NpmPackageStoreInfo providers are gathered from JsInfo. This is done directly from the npm_package_store_deps field of these. For linked npm package targets, the underlying npm_package_store target(s) that back the links is used.

Gathered NpmPackageStoreInfo providers are used downstream as direct dependencies when linking a downstream npm_package target with npm_link_package.

define

Optional dictionary: String → String. Default: {}

A dict of global identifier replacements. Values are subject to $(location ...) expansion. Example:

esbuild(
name = "bundle",
define = {
"process.env.NODE_ENV": "production"
},
)

See https://esbuild.github.io/api/#define for more details

deps

Optional list of labels. Default: []

[Must provide JsInfo]

A list of direct dependencies that are required to build the bundle

entry_point

Optional label. Default: None

The bundle's entry point (e.g. your main.js or app.js or index.js)

This is a shortcut for the entry_points attribute with a single entry. Specify either this attribute or entry_point, but not both.

entry_points

Optional list of labels. Default: []

The bundle's entry points (e.g. your main.js or app.js or index.js)

Specify either this attribute or entry_point, but not both.

external

Optional list of strings. Default: []

A list of module names that are treated as external and not included in the resulting bundle

See https://esbuild.github.io/api/#external for more details

format

Optional string. Default: ""

The output format of the bundle, defaults to iife when platform is browser and cjs when platform is node. If performing code splitting or multiple entry_points are specified, defaults to esm.

See https://esbuild.github.io/api/#format for more details

launcher

Optional label. Default: None

Override the default esbuild wrapper, which is supplied by the esbuild toolchain

max_threads

Optional integer. Default: 0

Sets the GOMAXPROCS variable to limit the number of threads that esbuild can run with. This can be useful if running many esbuild rule invocations in parallel, which has the potential to cause slowdown. For general use, leave this attribute unset.

metafile

Optional boolean. Default: False

If true, esbuild creates a metafile along with the output

minify

Optional boolean. Default: False

Minifies the bundle with the built in minification. Removes whitespace, shortens identifieres and uses equivalent but shorter syntax.

Sets all --minify-* flags

See https://esbuild.github.io/api/#minify for more details

output

Optional label.

Name of the output file when bundling

output_css

Optional label.

Declare a .css file will be output next to output bundle.

If your JS code contains import statements that import .css files, esbuild will place the content in a file next to the main output file, which you'll need to declare. If your output file is named 'foo.js', you should set this to 'foo.css'.

output_dir

Optional boolean. Default: False

If true, esbuild produces an output directory containing all output files

output_map

Optional label.

Name of the output source map when bundling

platform

Optional string. Default: "browser"

The platform to bundle for.

See https://esbuild.github.io/api/#platform for more details

sourcemap

Optional string. Default: ""

Defines where sourcemaps are output and how they are included in the bundle. If linked, a separate .js.map file is generated and referenced by the bundle. If external, a separate .js.map file is generated but not referenced by the bundle. If inline, a sourcemap is generated and its contents are inlined into the bundle (and no external sourcemap file is created). If both, a sourcemap is inlined and a .js.map file is created.

See https://esbuild.github.io/api/#sourcemap for more details

sources_content

Optional boolean. Default: False

If False, omits the sourcesContent field from generated source maps

See https://esbuild.github.io/api/#sources-content for more details

splitting

Optional boolean. Default: False

If true, esbuild produces an output directory containing all the output files from code splitting for multiple entry points

See https://esbuild.github.io/api/#splitting and https://esbuild.github.io/api/#entry-points for more details

srcs

Optional list of labels. Default: []

Source files to be made available to esbuild

target

Optional string. Default: "es2015"

Environment target (e.g. es2017, chrome58, firefox57, safari11, edge16, node10, esnext). Default es2015.

See https://esbuild.github.io/api/#target for more details

Macros and Functions

lib.implementation

Example usage (generated):

load("@aspect_rules_esbuild//esbuild/private:esbuild.bzl", "lib")

lib.implementation(
ctx = None,
)

ctx

Required.