我正在构建一个网站,并且在一个目录中有多个 js 文件。当我保存任何一个 js 文件时,我希望运行一个脚本,该脚本将使用 google 闭包编译器 jar 编译和压缩所有文件。
来自 Google Closure Compiler README 的示例:
java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
是否有执行此操作的 shell 脚本或应用程序?我正在寻找类似于 http://incident57.com/less/ 的东西适用于 CSS。
最佳答案
在 linux 中,您可以使用 inotifywait 命令来监听特定文件夹中的更改。 这个脚本你能给出一个想法吗:
#!/bin/bash
directory=$1
inotifywait -q -m --format '%f' -e modify -e move -e create -e delete ${directory} | while read line
do
echo "doing something with: $line";
# for example:
# java -jar compiler.jar --js=in1.js --js=in2.js ... --js_output_file=out.js
done
您可以通过这种方式调用指定“monitor”目录的脚本
./inotify.sh ~/Desktop/
关于javascript - 保存时自动编译和压缩js文件的脚本/应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3274704/