我最近决定开始使用谷歌的命令行JavaScript编译器(闭包编译器)来缩小我的web应用程序中的JavaScript。不幸的是,编译器是用Java编写的,所以我必须键入命令才能使用编译器,这有点麻烦:
java -jar compiler.jar --js hello.js --js_output_file hello-compiled.js对于我来说,将其封装在.bat文件中的最简单方法是什么,它允许我简单地输入closure hello.js hello-compiled.js,同时仍然允许我使用闭包的其他命令行标志,比如--warning-level和--help
发布于 2013-01-10 06:47:45
:Start
@echo off
if "%1"=="" Echo Error - input and output parameters were not specified.&goto End
if "%2"=="" Echo Error - output parameter was not specified.&goto End
if not exist %1 Echo Error - input file does not exist.&goto End
set infile=%1
set outfile=%2
set "params="
:Loop
if "%3"=="" goto Continue
set params=%params% %3
shift
goto Loop
:Continue
java -jar compiler.jar --js %infile% --js_output_file %outfile% %params%
set "infile="
set "outfile="
set "params="
:End 发布于 2013-01-10 17:56:32
我不知道你想让它自动化到什么程度,但是这将提示你输入你的脚本,你的编译输出文件,以及你是否需要任何额外的参数。
如果你想要更多的选项,可以很容易的编辑。
@echo off
set /p script=Script file:
set /p compiled=Compiled script:
set /p params=Enter any extra params (leave blank if none):
if defined params (
java -jar compiler.jar --js %script% --js_output_file %compiled% %params%
) else (
java -jar compiler.jar --js %script% --js_output_file %compiled%
)
echo Done
pause >nulhttps://stackoverflow.com/questions/14247267
复制相似问题