Skip to content

Commit

Permalink
feat(terser): add args attribute to support additional command line…
Browse files Browse the repository at this point in the history
… arguments

Terser only parses minify() args from the config_file so additional arguments such as --comments may
be passed to the rule this attribute. See https://github.com/terser/terser#command-line-usage for a list
of terser CLI options.
  • Loading branch information
gregmagolan authored and alexeagle committed Oct 30, 2019
1 parent c56b28d commit 563bad7
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/terser/src/terser_minified.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ If you want to do this, you can pass a filegroup here.""",
allow_files = [".js", ".map", ".mjs"],
mandatory = True,
),
"args": attr.string_list(
doc = """Additional command line arguments to pass to terser.
Terser only parses minify() args from the config file so additional arguments such as `--comments` may
be passed to the rule using this attribute. See https://github.com/terser/terser#command-line-usage for the
full list of terser CLI options.""",
),
"config_file": attr.label(
doc = """A JSON file containing Terser minify() options.
Expand Down Expand Up @@ -156,6 +163,7 @@ def _terser(ctx):
)

args.add_all(["--config-file", opts.path])
args.add_all(ctx.attr.args)

ctx.actions.run(
inputs = inputs,
Expand Down
16 changes: 16 additions & 0 deletions packages/terser/test/args/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test")
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")

terser_minified(
name = "out.min",
src = "input.js",
args = ["--comments"],
sourcemap = False,
)

golden_file_test(
name = "test",
actual = "out.min",
golden = "output.golden.js_",
golden_debug = "output.debug.golden.js_",
)
12 changes: 12 additions & 0 deletions packages/terser/test/args/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
class A {
doThing() {
console.error('thing');
}
}
12 changes: 12 additions & 0 deletions packages/terser/test/args/output.debug.golden.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
class A {
doThing() {
console.error("thing");
}
}
8 changes: 8 additions & 0 deletions packages/terser/test/args/output.golden.js_
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @license
* Copyright Google Inc. All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
class A{doThing(){console.error("thing")}}

0 comments on commit 563bad7

Please sign in to comment.