Skip to content

Commit 94c6182

Browse files
authored
feat(rollup): add args attribute to rollup_bundle rule (#1681)
Arguments passed to rollup. These can be used to override config file settings. These argument are appended to the command line before all arguments that are always added by the rule such as `--output.dir` or `--output.file`, `--format`, `--config` and `--preserveSymlinks` and also those that are optionally added by the rule such as `--sourcemap`. See rollup CLI docs https://rollupjs.org/guide/en/#command-line-flags for complete list of supported arguments.
1 parent 8089999 commit 94c6182

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

packages/rollup/src/rollup_bundle.bzl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,16 @@ You must not repeat file(s) passed to entry_point/entry_points.
6565
# Don't try to constrain the filenames, could be json, svg, whatever
6666
allow_files = True,
6767
),
68+
"args": attr.string_list(
69+
doc = """Command line arguments to pass to rollup. Can be used to override config file settings.
70+
71+
These argument passed on the command line before all arguments that are always added by the
72+
rule such as `--output.dir` or `--output.file`, `--format`, `--config` and `--preserveSymlinks` and
73+
also those that are optionally added by the rule such as `--sourcemap`.
74+
75+
See rollup CLI docs https://rollupjs.org/guide/en/#command-line-flags for complete list of supported arguments.""",
76+
default = [],
77+
),
6878
"config_file": attr.label(
6979
doc = """A rollup.config.js file
7080
@@ -286,6 +296,9 @@ def _rollup_bundle(ctx):
286296
# See CLI documentation at https://rollupjs.org/guide/en/#command-line-reference
287297
args = ctx.actions.args()
288298

299+
# Add user specified arguments *before* rule supplied arguments
300+
args.add_all(ctx.attr.args)
301+
289302
# List entry point argument first to save some argv space
290303
# Rollup doc says
291304
# When provided as the first options, it is equivalent to not prefix them with --input

packages/rollup/test/sourcemaps/BUILD.bazel

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
44
rollup_bundle(
55
name = "bundle",
66
srcs = ["s.js"],
7+
# Test existance of args attribute
8+
args = [
9+
"--environment",
10+
"FOO,BAR:baz",
11+
],
712
# Use the desugared form to assert that it works
813
entry_points = {"input.js": "bundle"},
914
sourcemap = "true",

0 commit comments

Comments
 (0)