Created
September 8, 2009 14:34
-
-
Save othree/182971 to your computer and use it in GitHub Desktop.
[vimrc] Auto compile JS/CSS file after saving it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Js_css_compress () | |
let cwd = expand('<afile>:p:h') | |
let nam = expand('<afile>:t:r') | |
let ext = expand('<afile>:e') | |
if -1 == match(nam, "[\._]src$") | |
let minfname = nam.".min.".ext | |
else | |
let minfname = substitute(nam, "[\._]src$", "", "g").".".ext | |
endif | |
if ext == 'less' | |
if executable('lessc') | |
cal system( 'lessc '.cwd.'/'.nam.'.'.ext.' &') | |
endif | |
else | |
if filewritable(cwd.'/'.minfname) | |
if ext == 'js' && executable('closure-compiler') | |
cal system( 'closure-compiler --js '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &') | |
elseif executable('yuicompressor') | |
cal system( 'yuicompressor '.cwd.'/'.nam.'.'.ext.' > '.cwd.'/'.minfname.' &') | |
endif | |
endif | |
endif | |
endfunction | |
autocmd FileWritePost,BufWritePost *.js :call Js_css_compress() | |
autocmd FileWritePost,BufWritePost *.css :call Js_css_compress() | |
autocmd FileWritePost,BufWritePost *.less :call Js_css_compress() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Plugin Version at https://github.com/othree/fecompressor.vim