0

タイトルにあるように、JavaAPIを介してプログラムで定義をGoogleClosureCompilerに渡したいと思います。

これは私の現在のコードです:

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());
}
4

1 に答える 1

0

置換の定義マップにデータを入力します。

options.getDefineReplacements().put("myDefineVarName", value);

Nodeは、ブール値、数値、または文字列リテラルである必要があります。ブールリテラルの値を作成するには、次のような値を使用します

new Node(Token.TRUE)

ここで、とは両方ともNodeパッケージTokenからのものcom.google.javascript.jscomp.rhinoです。

私は他の種類の値のトークンタイプであると信じToken.STRINGToken.NUMBERいますが、それについては引用しないでください。

于 2011-07-09T21:06:29.007 に答える