Skip to content

Latest commit

 

History

History
76 lines (55 loc) · 10.9 KB

esbuild.md

File metadata and controls

76 lines (55 loc) · 10.9 KB

esbuild rule

esbuild_bundle

esbuild_bundle(name, deps, srcs, data, args_file, bazel_sandbox_plugin, bundle, config, define,
               entry_point, entry_points, esbuild_log_level, external, format, js_log_level, launcher,
               max_threads, metafile, minify, node_toolchain, output, output_css, output_dir,
               output_map, platform, sourcemap, sources_content, splitting, target, tsconfig)

Runs the esbuild bundler under Bazel

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

Note: to prevent esbuild from following symlinks and leaving the bazel sandbox, a custom bazel-sandbox resolver plugin is used in this rule. See #58 for more info.

ATTRIBUTES

Name Description Type Mandatory Default
name A unique name for this target. Name required
deps A list of direct dependencies that are required to build the bundle List of labels optional []
srcs Source files to be made available to esbuild List of labels optional []
data Runtime dependencies to include in binaries/tests that depend on this target.

Follows the same semantics as js_library data attribute. See https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#data for more info.
List of labels optional []
args_file Internal use only Label optional None
bazel_sandbox_plugin If true, a custom bazel-sandbox plugin will be enabled that prevents esbuild from leaving the Bazel sandbox. See #160 for more info. Boolean optional True
bundle If true, esbuild will bundle the input files, inlining their dependencies recursively Boolean optional True
config Configuration file used for esbuild. Note that options set in this file may get overwritten. If you formerly used args from rules_nodejs' npm package @bazel/esbuild, replace it with this attribute. TODO: show how to write a config file that depends on plugins, similar to the esbuild_config macro in rules_nodejs. Label optional None
define 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
Dictionary: String -> String optional {}
entry_point 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.
Label optional None
entry_points 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.
List of labels optional []
esbuild_log_level Set the logging level of esbuild.

We set a default of "warmning" since the esbuild default of "info" includes an output file summary which is slightly redundant under Bazel and may lead to spammy bazel build output.

See https://esbuild.github.io/api/#log-level for more details.
String optional "warning"
external 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
List of strings optional []
format 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
String optional ""
js_log_level Set the logging level for js_binary launcher and the JavaScript bazel-sandbox plugin.

Log levels: fatal, error, warn, info, debug
String optional "error"
launcher Override the default esbuild wrapper, which is supplied by the esbuild toolchain Label optional None
max_threads 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. Integer optional 0
metafile If true, esbuild creates a metafile along with the output Boolean optional False
minify 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
Boolean optional False
node_toolchain The Node.js toolchain to use for this target.

See https://bazelbuild.github.io/rules_nodejs/Toolchains.html

Typically this is left unset so that Bazel automatically selects the right Node.js toolchain for the target platform. See https://bazel.build/extending/toolchains#toolchain-resolution for more information.
Label optional None
output Name of the output file when bundling Label optional None
output_css 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'.
Label optional None
output_dir If true, esbuild produces an output directory containing all output files Boolean optional False
output_map Name of the output source map when bundling Label optional None
platform The platform to bundle for.

See https://esbuild.github.io/api/#platform for more details
String optional "browser"
sourcemap 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
String optional ""
sources_content If False, omits the sourcesContent field from generated source maps

See https://esbuild.github.io/api/#sources-content for more details
Boolean optional False
splitting 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
Boolean optional False
target Environment target (e.g. es2017, chrome58, firefox57, safari11, edge16, node10, esnext). Default es2015.

See https://esbuild.github.io/api/#target for more details
String optional "es2015"
tsconfig TypeScript configuration file used by esbuild. Default to an empty file with no configuration.

See https://esbuild.github.io/api/#tsconfig for more details
Label required

lib.implementation

lib.implementation(ctx)

PARAMETERS

Name Description Default Value
ctx

-

none