Google 闭包编译器 ADVANCED_OPTIMIZATIONS 给我空文件

Google closure compiler with ADVANCED_OPTIMIZATIONS giving me empty file

我使用的命令是

java -jar closure-compiler-v20181028.jar --compilation_level ADVANCED_OPTIMIZATIONS --js_output_file=out.js input.js

我的 input.js 只包含

function base() {
    var b='xyz';
                if (b.tagName && 0 == b.tagName.search(this.TAGS_)) {
                    if (b.hasAttribute("href") && void 0 !== self.angular) {
                        var f = b.getAttribute("href");
                        if (f.indexOf("{{") >= 0 && f.indexOf("}}") > 0 && !b.hasAttribute("ng-href"))
                            return b.setAttribute("ng-href", f), void b.removeAttribute("href");
                    }
                    for (var a = 0; a < this.URL_ATTRIBUTES_.length; ++a)
                        if (b.hasAttribute(this.URL_ATTRIBUTES_[a]))
                            return this.updateAttributes_(b, a);
                }
            }

我尝试使用 gradle 脚本,结果也一样。如有任何帮助,我们将不胜感激。

如果您不调用 base(),代码将被删除,因为它无法访问。

您要么想要调用它,要么添加一个 @export 符号来告诉 Closure 其他代码需要它。

或者,如果有东西在调用 base(),它可能没有正确包含在您的构建中。

来自文档:

"...使用 ADVANCED_OPTIMIZATIONS 编译的代码可能无法与未编译的代码一起使用,除非您采取特殊步骤来确保互操作性。如果您不标记代码中引用的外部函数和属性,Closure Compiler 将不适当地重命名代码中的引用,导致代码中的名称与外部代码中的名称不匹配。"

这里的 "flag" 是指 "export"。有关更多信息,请参阅有关不同编译级别的文档:

https://developers.google.com/closure/compiler/docs/compilation_levels

此博客post:

http://closuretools.blogspot.com/2012/09/which-compilation-level-is-right-for-me.html

关于出口的文件在这里:

https://developers.google.com/closure/compiler/docs/api-tutorial3