rules.md

May 7, 2026 ยท View on GitHub

Public API surface is re-exported here.

Users should not load files under "/internal"

webpack_bundle

load("@aspect_rules_webpack//webpack:defs.bzl", "webpack_bundle")

webpack_bundle(name, node_modules, srcs, args, deps, chdir, data, env, output_dir, entry_point,
               entry_points, webpack_config, configure_mode, configure_devtool,
               use_execroot_entry_point, supports_workers, kwargs)

Runs the webpack-cli under bazel

PARAMETERS

NameDescriptionDefault Value
nameA unique name for this target.none
node_modulesLabel 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
none
srcsNon-entry point JavaScript source files from the workspace.

You must not repeat file(s) passed to entry_point/entry_points.
[]
argsCommand 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 for a complete list of supported arguments.
[]
depsRuntime dependencies which may be loaded during compilation.[]
chdirWorking 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
None
dataRuntime 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.
[]
envEnvironment variables of the action.

Subject to $(location) and make variable expansion.
{}
output_dirIf True, webpack produces an output directory containing all output files.False
entry_pointThe point where to start the application bundling process.

See https://webpack.js.org/concepts/entry-points/

Exactly one of entry_point to entry_points must be specified if output_dir is False.
None
entry_pointsThe map of entry points to bundle names.

See https://webpack.js.org/concepts/entry-points/

Exactly one of entry_point to entry_points must be specified if output_dir is False.
{}
webpack_configWebpack configuration file.

See https://webpack.js.org/configuration/
None
configure_modeConfigure 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 for more info on how to configure the compilation mode.
True
configure_devtoolConfigure 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 for more info on how to configure the compilation mode.
True
use_execroot_entry_pointUse 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.
True
supports_workersExperimental! Use only with caution.

Allows you to enable the Bazel Worker strategy for this library.
False
kwargsAdditional argumentsnone

webpack_devserver

load("@aspect_rules_webpack//webpack:defs.bzl", "webpack_devserver")

webpack_devserver(name, node_modules, chdir, env, entry_point, entry_points, webpack_config,
                  configure_mode, configure_devtool, args, data, mode, kwargs)

Runs the webpack devserver.

This is a macro that uses js_run_devserver 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.

PARAMETERS

NameDescriptionDefault Value
nameA unique name for this target.none
node_modulesLabel 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
none
chdirWorking 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
None
envEnvironment variables of the action.

Subject to $(location) and make variable expansion.
{}
entry_pointThe point where to start the application bundling process.

See https://webpack.js.org/concepts/entry-points/

Only one of entry_point to entry_points must be specified.
None
entry_pointsThe map of entry points to bundle names.

See https://webpack.js.org/concepts/entry-points/

Only one of entry_point to entry_points must be specified.
{}
webpack_configWebpack configuration file. See https://webpack.js.org/configuration/.None
configure_modeConfigure 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 for more info on how to configure the compilation mode.
True
configure_devtoolConfigure 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 for more info on how to configure the compilation mode.
True
argsAdditional arguments to pass to webpack.

The serve command, the webpack config file (--config) and the mode (--mode) are automatically set.
[]
dataBundle 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.
[]
modeThe mode to pass to --mode."development"
kwargsAdditional arguments. See js_run_devserver.none