我可以这样导入闭包编译器:
const ClosureCompiler = require('google-closure-compiler').compiler;
,但它使用Java版本。我对工作中的构建机器有一个限制,因此我不能使用java。我希望强制编译使用本机版本。我试过这样做:
const ClosureCompiler = require('google-closure-compiler-osx').compiler;
这似乎导致ClosureCompiler未定义。我已经走了一圈又一圈,试图找到任何关于API暴露给javascript的文档,但我一直没有提出任何东西。
如果有人有关于如何强制本地编译而不是java编译的想法,我将不胜感激。
我想通过查看node_modules/google-close -compiler内的cli.js和util.js文件中发生的事情,我已经在这方面取得了一些进展。
这个模式似乎有效:
const ClosureCompiler = require('google-closure-compiler').compiler,
compilerInstance = new ClosureCompiler({... setup opts ...});
// Force native compilation
let compilerPlatform = 'linux';
switch (process.platform) {
case 'win32': compilerPlatform = 'windows'; break;
case 'darwin': compilerPlatform = 'osx'; break;
}
compilerInstance.JAR_PATH = null;
compilerInstance.javaPath = require('google-closure-compiler-' + compilerPlatform);
compilerInstance.run((exitCode, stdOut, stdErr) => {
... do some stuff ...
});