> ## Documentation Index
> Fetch the complete documentation index at: https://site.aspect.build/llms.txt
> Use this file to discover all available pages before exploring further.

# @aspect_rules_esbuild//esbuild:defs.bzl

> Bazel rules_esbuild public API: esbuild_bundle rule for bundling JavaScript and TypeScript with the esbuild compiler under Bazel and rules_js.

<Callout icon="book">
  Documentation for [@aspect\_rules\_esbuild@v0.25.0](https://registry.bazel.build/modules/aspect_rules_esbuild/0.25.0) -- <Icon icon="github" iconType="brands" /> [View source](https://github.com/aspect-build/rules_esbuild/blob/v0.25.0/esbuild/defs.bzl)
</Callout>

# Public API

## Rule: `esbuild_bundle`

Runs the esbuild bundler under Bazel

For further information about esbuild, see [https://esbuild.github.io/](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 [https://github.com/aspect-build/rules\_esbuild/issues/58](https://github.com/aspect-build/rules_esbuild/issues/58) for more info.

### Attributes

<ParamField body="name" type="name" required>
  A unique name for this target.
</ParamField>

<ParamField body="args_file" type="label" default={`None`}>
  Internal use only
</ParamField>

<ParamField body="define" type="dictionary: String → String" default={`{}`}>
  A dict of global identifier replacements. Values are subject to \$(location ...) expansion.
  Example:

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

  See [https://esbuild.github.io/api/#define](https://esbuild.github.io/api/#define) for more details
</ParamField>

<ParamField body="deps" type="list of labels" default={`[]`}>
  A list of direct dependencies that are required to build the bundle
</ParamField>

<ParamField body="data" type="list of labels" default={`[]`}>
  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](https://docs.aspect.build/rulesets/aspect_rules_js/docs/js_library#data) for more info.
</ParamField>

<ParamField body="entry_point" type="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.
</ParamField>

<ParamField body="entry_points" type="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.
</ParamField>

<ParamField body="external" type="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](https://esbuild.github.io/api/#external) for more details
</ParamField>

<ParamField body="format" type="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](https://esbuild.github.io/api/#format) for more details
</ParamField>

<ParamField body="launcher" type="label" default={`None`}>
  Override the default esbuild wrapper, which is supplied by the esbuild toolchain
</ParamField>

<ParamField body="max_threads" type="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.
</ParamField>

<ParamField body="metafile" type="boolean" default={`False`}>
  If true, esbuild creates a metafile along with the output
</ParamField>

<ParamField body="minify" type="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](https://esbuild.github.io/api/#minify) for more details
</ParamField>

<ParamField body="output" type="label" default={`None`}>
  Name of the output file when bundling
</ParamField>

<ParamField body="output_css" type="label" default={`None`}>
  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'.
</ParamField>

<ParamField body="output_dir" type="boolean" default={`False`}>
  If true, esbuild produces an output directory containing all output files
</ParamField>

<ParamField body="output_map" type="label" default={`None`}>
  Name of the output source map when bundling
</ParamField>

<ParamField body="platform" type="string" default={`browser`}>
  The platform to bundle for.

  See [https://esbuild.github.io/api/#platform](https://esbuild.github.io/api/#platform) for more details
</ParamField>

<ParamField body="sourcemap" type="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](https://esbuild.github.io/api/#sourcemap) for more details
</ParamField>

<ParamField body="sources_content" type="boolean" default={`False`}>
  If False, omits the `sourcesContent` field from generated source maps

  See [https://esbuild.github.io/api/#sources-content](https://esbuild.github.io/api/#sources-content) for more details
</ParamField>

<ParamField body="splitting" type="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](https://esbuild.github.io/api/#splitting) and [https://esbuild.github.io/api/#entry-points](https://esbuild.github.io/api/#entry-points) for more details
</ParamField>

<ParamField body="srcs" type="list of labels" default={`[]`}>
  Source files to be made available to esbuild
</ParamField>

<ParamField body="target" type="list of strings" default={`["es2015"]`}>
  Environment target (e.g. es2017, chrome58, firefox57, safari11,
  edge16, node10, esnext). Default es2015.

  See [https://esbuild.github.io/api/#target](https://esbuild.github.io/api/#target) for more details
</ParamField>

<ParamField body="bundle" type="boolean" default={`True`}>
  If true, esbuild will bundle the input files, inlining their dependencies recursively
</ParamField>

<ParamField body="config" type="label" default={`None`}>
  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.
</ParamField>

<ParamField body="tsconfig" type="label" required>
  TypeScript configuration file used by esbuild. Default to an empty file with no configuration.

  See [https://esbuild.github.io/api/#tsconfig](https://esbuild.github.io/api/#tsconfig) for more details
</ParamField>

<ParamField body="bazel_sandbox_plugin" type="boolean" default={`True`}>
  If true, a custom bazel-sandbox plugin will be enabled that prevents esbuild from leaving the Bazel sandbox.
  See [https://github.com/aspect-build/rules\_esbuild/pull/160](https://github.com/aspect-build/rules_esbuild/pull/160) for more info.
</ParamField>

<ParamField body="esbuild_log_level" type="string" default={`warning`}>
  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](https://esbuild.github.io/api/#log-level) for more details.
</ParamField>

<ParamField body="js_log_level" type="string" default={`error`}>
  Set the logging level for js\_binary launcher and the JavaScript bazel-sandbox plugin.

  Log levels: fatal, error, warn, info, debug
</ParamField>

<ParamField body="node_toolchain" type="label" default={`None`}>
  The Node.js toolchain to use for this target.

  See [https://bazelbuild.github.io/rules\_nodejs/Toolchains.html](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](https://bazel.build/extending/toolchains#toolchain-resolution)
  for more information.
</ParamField>

## Function: `esbuild`

esbuild helper macro around the `esbuild_bundle` rule

For a full list of attributes, see the [`esbuild_bundle`](#rule-esbuild_bundle) rule

### Parameters

<ParamField body="name" type="unknown" required>
  The name used for this rule and output files
</ParamField>

<ParamField body="output_dir" type="unknown" default={`False`}>
  If `True`, produce an output directory
</ParamField>

<ParamField body="splitting" type="unknown" default={`False`}>
  If `True`, produce a code split bundle in the output directory
</ParamField>

<ParamField body="config" type="unknown" default={`None`}>
  an esbuild configuration file
  Can be a dictionary.
  In this case it is converted to json, and a config file is generated
  which exports the resulting object, e.g.
  `export default {...}`
</ParamField>

<ParamField body="kwargs" type="unknown">
  All other args from `esbuild_bundle`
</ParamField>
