Closure Compiler - 在命令行中解析Javascript而不从磁盘读取它?

Sea*_*ter 3 google-closure-compiler

我在脚本中调用Closure Compiler(closurecompiler.jar).该脚本还生成一些Closure Compiler需要编译的javascript.有没有办法解析这个javascript到Closure Compiler而不将其写入磁盘并阅读它--js.

wha*_*mma 6

如果未指定--js参数,则编译器将从标准输入中读取.这完全取决于您正在使用的操作系统和脚本语言,但您应该能够打开子流程的管道并写入它.如果您在Linux/Mac/Unix上使用PHP,例如:

<?php
$descriptorspec = array(
   0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
   1 => array("pipe", "w")   // stdout is a pipe that the child will write to
);

$process = proc_open('/path/to/java -jar compiler.jar', $descriptorspec, $pipes);

// Write the source script to the compiler
fwrite($pipes[0], $string_that_contains_your_script);
fclose($pipes[0]);

// Get the results
$compiled_script = stream_get_contents($pipes[1]);
fclose($pipes[1]);

$return_value = proc_close($process);
Run Code Online (Sandbox Code Playgroud)

你应该能够适应任何语言.