> ## 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_webpack//webpack:defs.bzl

> Bazel rules_webpack public API: webpack_bundle, webpack_devserver, and related rules for bundling JavaScript and TypeScript with webpack under Bazel.

<Callout icon="book">
  Documentation for [@aspect\_rules\_webpack@v0.17.1](https://registry.bazel.build/modules/aspect_rules_webpack/0.17.1) -- <Icon icon="github" iconType="brands" /> [View source](https://github.com/aspect-build/rules_webpack/blob/v0.17.1/webpack/defs.bzl)
</Callout>

Public API surface is re-exported here.

Users should not load files under "/internal"

## Function: `webpack_bundle`

Runs the webpack-cli under bazel

### Parameters

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

<ParamField body="node_modules" type="unknown" required>
  Label pointing to the linked node\_modules target where
  webpack is linked, e.g. `//:node_modules`.

  The following packages must be linked into the node\_modules supplied:

  webpack, webpack-cli
</ParamField>

<ParamField body="srcs" type="unknown" default={`[]`}>
  Non-entry point JavaScript source files from the workspace.

  You must not repeat file(s) passed to entry\_point/entry\_points.
</ParamField>

<ParamField body="args" type="unknown" default={`[]`}>
  Command line arguments to pass to Webpack.

  These argument passed on the command line before arguments that are added by the rule.
  Run `bazel` with `--subcommands` to see what Webpack CLI command line was invoked.

  See the [Webpack CLI docs](https://webpack.js.org/api/cli/) for a complete list of supported arguments.
</ParamField>

<ParamField body="deps" type="unknown" default={`[]`}>
  Runtime dependencies which may be loaded during compilation.
</ParamField>

<ParamField body="chdir" type="unknown" default={`None`}>
  Working directory to run Webpack under.

  This is needed to workaround some buggy resolvers in webpack loaders, which assume that the
  node\_modules tree is located in a parent of the working directory rather than a parent of
  the script with the require statement.

  Note that any relative paths in your configuration may need to be adjusted so they are
  relative to the new working directory.

  See also:
  [https://github.com/aspect-build/rules\_js/blob/main/docs/js\_binary.md#js\_binary-chdir](https://github.com/aspect-build/rules_js/blob/main/docs/js_binary.md#js_binary-chdir)
</ParamField>

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

<ParamField body="env" type="unknown" default={`{}`}>
  Environment variables of the action.

  Subject to `$(location)` and make variable expansion.
</ParamField>

<ParamField body="output_dir" type="unknown" default={`False`}>
  If True, webpack produces an output directory containing all output files.
</ParamField>

<ParamField body="entry_point" type="unknown" default={`None`}>
  The point where to start the application bundling process.

  See [https://webpack.js.org/concepts/entry-points/](https://webpack.js.org/concepts/entry-points/)

  Exactly one of `entry_point` to `entry_points` must be specified if `output_dir` is `False`.
</ParamField>

<ParamField body="entry_points" type="unknown" default={`{}`}>
  The map of entry points to bundle names.

  See [https://webpack.js.org/concepts/entry-points/](https://webpack.js.org/concepts/entry-points/)

  Exactly one of `entry_point` to `entry_points` must be specified if `output_dir` is `False`.
</ParamField>

<ParamField body="webpack_config" type="unknown" default={`None`}>
  Webpack configuration file.

  See [https://webpack.js.org/configuration/](https://webpack.js.org/configuration/)
</ParamField>

<ParamField body="configure_mode" type="unknown" default={`True`}>
  Configure `mode` in the generated base webpack config.

  `mode` is set to `production` if the Bazel compilation mode is `opt` otherwise it is set to `development`.

  The configured value will be overridden if it is set in a supplied `webpack_config`.

  See [https://bazel.build/docs/user-manual#compilation-mode](https://bazel.build/docs/user-manual#compilation-mode) for more info on how to configure the compilation mode.
</ParamField>

<ParamField body="configure_devtool" type="unknown" default={`True`}>
  Configure `devtool` in the generated base webpack config.

  `devtool` is set to `eval` if the Bazel compilation mode is `fastbuild`, `eval-source-map` if the Bazel
  compilation mode is `dbg`, otherwise it is left unset.

  The configured value will be overridden if it is set in a supplied `webpack_config`.

  See [https://bazel.build/docs/user-manual#compilation-mode](https://bazel.build/docs/user-manual#compilation-mode) for more info on how to configure the compilation mode.
</ParamField>

<ParamField body="use_execroot_entry_point" type="unknown" default={`True`}>
  Use the `entry_point` script of the `webpack` `js_binary` that is in the execroot output tree instead of the copy that is in runfiles.

  When set, runfiles are hoisted to the target platform when this is configured and included as target
  platform execroot inputs to the action.

  Using the entry point script that is in the execroot output tree means that there will be no conflicting
  runfiles `node_modules` in the node\_modules resolution path which can confuse npm packages such as next and
  react that don't like being resolved in multiple node\_modules trees. This more closely emulates the
  environment that tools such as Next.js see when they are run outside of Bazel.
</ParamField>

<ParamField body="supports_workers" type="unknown" default={`False`}>
  Experimental! Use only with caution.

  Allows you to enable the Bazel Worker strategy for this library.
</ParamField>

<ParamField body="kwargs" type="unknown">
  Additional arguments
</ParamField>

## Function: `webpack_devserver`

Runs the webpack devserver.

This is a macro that uses
[js\_run\_devserver](https://github.com/aspect-build/rules_js/blob/main/docs/js_run_devserver.md)
under the hood.

When using ibazel, the devserver will automatically reload when the source files change. Note that
ibazel does not work when using bazel `alias` targets, see [https://github.com/bazelbuild/bazel-watcher/issues/100](https://github.com/bazelbuild/bazel-watcher/issues/100).

### Parameters

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

<ParamField body="node_modules" type="unknown" required>
  Label pointing to the linked node\_modules target where
  webpack is linked, e.g. `//:node_modules`.

  The following packages must be linked into the node\_modules supplied:

  webpack, webpack-cli, webpack-dev-server
</ParamField>

<ParamField body="chdir" type="unknown" default={`None`}>
  Working directory to run Webpack under.

  This is needed to workaround some buggy resolvers in webpack loaders, which assume that the
  node\_modules tree is located in a parent of the working directory rather than a parent of
  the script with the require statement.

  Note that any relative paths in your configuration may need to be adjusted so they are
  relative to the new working directory.

  See also:
  [https://github.com/aspect-build/rules\_js/blob/main/docs/js\_binary.md#js\_binary-chdir](https://github.com/aspect-build/rules_js/blob/main/docs/js_binary.md#js_binary-chdir)
</ParamField>

<ParamField body="env" type="unknown" default={`{}`}>
  Environment variables of the action.

  Subject to `$(location)` and make variable expansion.
</ParamField>

<ParamField body="entry_point" type="unknown" default={`None`}>
  The point where to start the application bundling process.

  See [https://webpack.js.org/concepts/entry-points/](https://webpack.js.org/concepts/entry-points/)

  Only one of `entry_point` to `entry_points` must be specified.
</ParamField>

<ParamField body="entry_points" type="unknown" default={`{}`}>
  The map of entry points to bundle names.

  See [https://webpack.js.org/concepts/entry-points/](https://webpack.js.org/concepts/entry-points/)

  Only one of `entry_point` to `entry_points` must be specified.
</ParamField>

<ParamField body="webpack_config" type="unknown" default={`None`}>
  Webpack configuration file. See [https://webpack.js.org/configuration/](https://webpack.js.org/configuration/).
</ParamField>

<ParamField body="configure_mode" type="unknown" default={`True`}>
  Configure `mode` in the generated base webpack config.

  `mode` is set to `production` if the Bazel compilation mode is `opt` otherwise it is set to `development`.

  The configured value will be overridden if it is set in a supplied `webpack_config`.

  See [https://bazel.build/docs/user-manual#compilation-mode](https://bazel.build/docs/user-manual#compilation-mode) for more info on how to configure the compilation mode.
</ParamField>

<ParamField body="configure_devtool" type="unknown" default={`True`}>
  Configure `devtool` in the generated base webpack config.

  `devtool` is set to `eval` if the Bazel compilation mode is `fastbuild`, `eval-source-map` if the Bazel
  compilation mode is `dbg`, otherwise it is left unset.

  The configured value will be overridden if it is set in a supplied `webpack_config`.

  See [https://bazel.build/docs/user-manual#compilation-mode](https://bazel.build/docs/user-manual#compilation-mode) for more info on how to configure the compilation mode.
</ParamField>

<ParamField body="args" type="unknown" default={`[]`}>
  Additional arguments to pass to webpack.

  The `serve` command, the webpack config file (`--config`) and the mode (`--mode`) are
  automatically set.
</ParamField>

<ParamField body="data" type="unknown" default={`[]`}>
  Bundle and runtime dependencies of the program.

  Should include the `webpack_bundle` rule `srcs` and `deps`.

  The webpack config and entry\_point\[s] are automatically passed to data and should not be repeated.
</ParamField>

<ParamField body="mode" type="unknown" default={`development`}>
  The mode to pass to `--mode`.
</ParamField>

<ParamField body="kwargs" type="unknown">
  Additional arguments. See [js\_run\_devserver](https://github.com/aspect-build/rules_js/blob/main/docs/js_run_devserver.md).
</ParamField>
