スクリプト内から Closure Compiler (closurecompiler.jar) を呼び出しています。このスクリプトは、Closure Compiler がコンパイルする必要のある JavaScript も生成しています。この JavaScript をディスクに書き込んで--js
.
質問する
523 次
1 に答える
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);
これをほぼすべての言語に適応させることができるはずです。
于 2012-11-19T19:26:01.257 に答える