通过 Java 将定义传递给 Google Closure 编译器
正如标题所示,我想通过 Java API 以编程方式将定义传递给 Google Closure 编译器。
这是我当前的代码:
com.google.javascript.jscomp.Compiler.setLoggingLevel(Level.INFO);
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
List<JSSourceFile> externs = new ArrayList<JSSourceFile>();
externs.add(JSSourceFile.fromFile(extern_src));
List<JSSourceFile> primary = new ArrayList<JSSourceFile>();
primary.add(JSSourceFile.fromFile(tmp));
compiler.compile(externs, primary, options);
for (JSError message : compiler.getWarnings()) {
System.err.println("Warning message: " + message.toString());
}
for (JSError message : compiler.getErrors()) {
System.err.println("Error message: " + message.toString());
}
As the title says, I'd like to pass defines programmatically via the Java API to the Google Closure Compiler.
This is my current code:
com.google.javascript.jscomp.Compiler.setLoggingLevel(Level.INFO);
com.google.javascript.jscomp.Compiler compiler = new com.google.javascript.jscomp.Compiler();
CompilerOptions options = new CompilerOptions();
CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options);
WarningLevel.VERBOSE.setOptionsForWarningLevel(options);
List<JSSourceFile> externs = new ArrayList<JSSourceFile>();
externs.add(JSSourceFile.fromFile(extern_src));
List<JSSourceFile> primary = new ArrayList<JSSourceFile>();
primary.add(JSSourceFile.fromFile(tmp));
compiler.compile(externs, primary, options);
for (JSError message : compiler.getWarnings()) {
System.err.println("Warning message: " + message.toString());
}
for (JSError message : compiler.getErrors()) {
System.err.println("Error message: " + message.toString());
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您想要填充 定义替换地图。
该值必须是一个
Node
,它是布尔值、数字或字符串文字。值
要为布尔文字创建值,请使用类似于
Node
和Token
均来自包com.google.javascript.jscomp.rhino
的 >。我相信 Token.STRING 和 Token.NUMBER 是其他类型值的令牌类型,但不要引用我的观点。
You want to populate the define replacements map.
The value has to be a
Node
that is a boolean, numeric, or string literal.To create a value for a boolean literal use a value like
where both
Node
andToken
are from the packagecom.google.javascript.jscomp.rhino
.I believe
Token.STRING
andToken.NUMBER
are the token types for the other kinds of values but don't quote me on that.