Skip to content

Commit 563bad7

Browse files
gregmagolanalexeagle
authored andcommitted
feat(terser): add args attribute to support additional command line 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.
1 parent c56b28d commit 563bad7

5 files changed

Lines changed: 56 additions & 0 deletions

File tree

packages/terser/src/terser_minified.bzl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ If you want to do this, you can pass a filegroup here.""",
4343
allow_files = [".js", ".map", ".mjs"],
4444
mandatory = True,
4545
),
46+
"args": attr.string_list(
47+
doc = """Additional command line arguments to pass to terser.
48+
49+
Terser only parses minify() args from the config file so additional arguments such as `--comments` may
50+
be passed to the rule using this attribute. See https://github.com/terser/terser#command-line-usage for the
51+
full list of terser CLI options.""",
52+
),
4653
"config_file": attr.label(
4754
doc = """A JSON file containing Terser minify() options.
4855
@@ -156,6 +163,7 @@ def _terser(ctx):
156163
)
157164

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

160168
ctx.actions.run(
161169
inputs = inputs,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
load("@build_bazel_rules_nodejs//internal/golden_file_test:golden_file_test.bzl", "golden_file_test")
2+
load("@npm_bazel_terser//:index.from_src.bzl", "terser_minified")
3+
4+
terser_minified(
5+
name = "out.min",
6+
src = "input.js",
7+
args = ["--comments"],
8+
sourcemap = False,
9+
)
10+
11+
golden_file_test(
12+
name = "test",
13+
actual = "out.min",
14+
golden = "output.golden.js_",
15+
golden_debug = "output.debug.golden.js_",
16+
)

packages/terser/test/args/input.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
class A {
9+
doThing() {
10+
console.error('thing');
11+
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
class A {
9+
doThing() {
10+
console.error("thing");
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/**
2+
* @license
3+
* Copyright Google Inc. All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.io/license
7+
*/
8+
class A{doThing(){console.error("thing")}}

0 commit comments

Comments
 (0)