以下是涵盖多个输入文件的五种globbing技术,文档提取自CommandLineRunner
类:
(1) 这是muka的技巧的一种变化形式,去除了不必要的--js
标志:
java -jar compiler.jar \
--js_output_file build/out.js `find ./src/*.js`
根据文档:
--js
标志名是可选的,因为参数默认被解释为文件。
这将包括 /src/
中所有的 .js
文件,但不会包括 /src/
的子目录中的任何文件。
(2) 与1类似,但将包括 /src/
及其所有子目录中的所有 .js
文件:
java -jar compiler.jar \
--js_output_file build/out.js `find ./src/ -name '*.js'`
(3) 类似于2,但使用 xargs
:
find ./src/ -name '*.js' \
| xargs java -jar compiler.jar \
--js_output_file build/out.js \
--manage_closure_dependencies
从文档中得知:
It is convenient to leverage the additional arguments feature when using the
Closure Compiler in combination with find
and xargs
:
find MY_JS_SRC_DIR -name '*.js' \
| xargs java -jar compiler.jar --manage_closure_dependencies
The find
command will produce a list of '*.js' source files in
the MY_JS_SRC_DIR
directory while xargs
will convert them
to a single, space-delimited set of arguments that are appended to the
java
command to run the Compiler.
Note that it is important to use the
--manage_closure_dependencies
option in this case because the
order produced by find
is unlikely to be sorted correctly with
respect to goog.provide()
and goog.requires()
.
(4) 在发布版本v20140625中,添加了对**
(globstar)通配符的支持,该通配符递归匹配所有子目录。
例如,这将包括/src/
及其所有子目录中的所有.js
文件:
java -jar compiler.jar \
--js_output_file build/out.js './src/**.js'
更多信息在此处。根据文档:
You may also use minimatch-style glob patterns. For example, use:
--js='**.js' --js='!**_test.js'
to recursively include all js files that do not end in _test.js
从Java文档中得知:
以下规则用于解释glob模式:
*
字符匹配零个或多个名称组件的字符,不跨越目录边界。
**
字符匹配零个或多个字符,跨越目录边界。
(5) v20140625版本还添加了一个新功能:如果输入路径是目录,则该目录及其所有子目录中的所有.js
文件都将被包含。
例如,这将包括/src/
及其所有子目录中的所有.js
文件:
java -jar compiler.jar \
--js_output_file build/out.js './src/'
更多信息请点击 此处。