正如标题所说,我想通过 Java API 以编程方式将定义传递给 Google Closure Compiler。
这是我当前的代码:
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());
}