A simple way to automatically compile Javascript files using Google Closure (and save the compiled results to a different file - filename.js saves as both filename.js and filename.min.js)
The regular way
- Edit .js file
- Save .js file
- Link it in .html file
- Compile .js file
- Link compiled version in .html file
- Edit .js file
- Save .js file
- Forget to compile it
- Become frustrated because the compiled version is still linked in .html file
This way
- Edit .js file
- Save .js file
- Link compiled version in .html
- Edit .js file
- Save .js file
- Test (because it's automatically compiled!)
Auto Compile
Add this to your .vimrc file, while changing the path in "cpa"
autocmd BufWriteCmd *.js :call Compile_JS()
function! Compile_JS()
if &modified
write
let fn = expand('%:p')
let pn = expand('%:p:h')
let fnm = expand('%:r.js')
let cpa = "/home/username/closure/compiler.jar"
execute "! java -jar " . cpa . " --js=" . fn . " --js_output_file=" . pn . "/" . fnm . ".min.js"
endif
endfunction
Please email the author (Danny Sterne) to provide feedback on this tip.