Skip to content

Commit

Permalink
feat(rollup): add args attribute to rollup_bundle rule (#1681)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gregmagolan authored Mar 2, 2020
1 parent 8089999 commit 94c6182
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions packages/rollup/src/rollup_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ You must not repeat file(s) passed to entry_point/entry_points.
# Don't try to constrain the filenames, could be json, svg, whatever
allow_files = True,
),
"args": attr.string_list(
doc = """Command line arguments to pass to rollup. Can be used to override config file settings.
These argument passed on 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.""",
default = [],
),
"config_file": attr.label(
doc = """A rollup.config.js file
Expand Down Expand Up @@ -286,6 +296,9 @@ def _rollup_bundle(ctx):
# See CLI documentation at https://rollupjs.org/guide/en/#command-line-reference
args = ctx.actions.args()

# Add user specified arguments *before* rule supplied arguments
args.add_all(ctx.attr.args)

# List entry point argument first to save some argv space
# Rollup doc says
# When provided as the first options, it is equivalent to not prefix them with --input
Expand Down
5 changes: 5 additions & 0 deletions packages/rollup/test/sourcemaps/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ load("@npm_bazel_rollup//:index.from_src.bzl", "rollup_bundle")
rollup_bundle(
name = "bundle",
srcs = ["s.js"],
# Test existance of args attribute
args = [
"--environment",
"FOO,BAR:baz",
],
# Use the desugared form to assert that it works
entry_points = {"input.js": "bundle"},
sourcemap = "true",
Expand Down

0 comments on commit 94c6182

Please sign in to comment.