Public API for rollup rules
Rules
rollup_bundle
Runs the rollup.js CLI under Bazel.
name
A unique name for this target.
args
Command line arguments to pass to Rollup. Can be used to override config file settings.
These argument passed on the command line before arguments that are added by the rule.
Run bazel
with --subcommands
to see what Rollup CLI command line was invoked.
See the Rollup CLI docs for a complete list of supported arguments.
config_file
A rollup.config.js
file
Passed to the --config
option, see the config doc
If not set, a default basic Rollup config is used.
deps
Other libraries that are required by the code, or by the rollup.config.js
entry_point
The bundle's entry point (e.g. your main.js or app.js or index.js).
This is just a shortcut for the entry_points
attribute with a single output chunk named the same as the rule.
For example, these are equivalent:
rollup_bundle(
name = "bundle",
entry_point = "index.js",
)
rollup_bundle(
name = "bundle",
entry_points = {
"index.js": "bundle"
}
)
If rollup_bundle
is used on a ts_library
, the rollup_bundle
rule handles selecting the correct outputs from ts_library
.
In this case, entry_point
can be specified as the .ts
file and rollup_bundle
will handle the mapping to the .mjs
output file.
For example:
ts_library(
name = "foo",
srcs = [
"foo.ts",
"index.ts",
],
)
rollup_bundle(
name = "bundle",
deps = [ "foo" ],
entry_point = "index.ts",
)
entry_points
The bundle's entry points (e.g. your main.js or app.js or index.js).
Passed to the --input
option in Rollup.
Keys in this dictionary are labels pointing to .js entry point files. Values are the name to be given to the corresponding output chunk.
Either this attribute or entry_point
must be specified, but not both.
format
Specifies the format of the generated bundle. One of the following:
amd
: Asynchronous Module Definition, used with module loaders like RequireJScjs
: CommonJS, suitable for Node and other bundlersesm
: Keep the bundle as an ES module file, suitable for other bundlers and inclusion as a<script type=module>
tag in modern browsersiife
: A self-executing function, suitable for inclusion as a<script>
tag. (If you want to create a bundle for your application, you probably want to use this.)umd
: Universal Module Definition, works as amd, cjs and iife all in onesystem
: Native format of the SystemJS loader
link_workspace_root
Link the workspace root to the bin_dir to support absolute requires like 'my_wksp/path/to/file'. If source files need to be required then they can be copied to the bin_dir with copy_to_bin.
node_context_data
Provides info about the build context, such as stamping.
By default it reads from the bazel command line, such as the --stamp
argument.
Use this to override values for this target, such as enabling or disabling stamping.
You can use the node_context_data
rule in @build_bazel_rules_nodejs//internal/node:context.bzl
to create a NodeContextInfo.
output_dir
Whether to produce a directory output.
We will use the --output.dir
option in rollup
rather than --output.file
.
If the program produces multiple chunks, you must specify this attribute. Otherwise, the outputs are assumed to be a single file.
rollup_bin
Target that executes the rollup binary
rollup_worker_bin
Internal use only
silent
Whether to execute the rollup binary with the --silent flag, defaults to False.
Using --silent can cause rollup to ignore errors/warnings which are only surfaced via logging. Since bazel expects printing nothing on success, setting silent to True is a more Bazel-idiomatic experience, however could cause rollup to drop important warnings.
sourcemap
Whether to produce sourcemaps.
Passed to the --sourcemap
option in Rollup
srcs
Non-entry point JavaScript source files from the workspace.
You must not repeat file(s) passed to entry_point/entry_points.
supports_workers
Experimental! Use only with caution.
Allows you to enable the Bazel Worker strategy for this library. When enabled, this rule invokes the "rollup_worker_bin" worker aware binary rather than "rollup_bin".