简体   繁体   English

每当我在Vim中保存其“源文件”时,如何自动更新或压缩CSS,JS和HTML文件?

[英]How to automatically update or compress a CSS, JS and HTML file every time I save its “source file” in Vim?

I wanted to minimize or compress CSS, Javascript and maybe Html files like Google does. 我想最小化或压缩CSS,Javascript,也许像Google那样压缩HTML文件。 Because, I used Google's Page-Speed and it recommended me to compress files. 因为,我使用了Google的Page-Speed,它建议我压缩文件。 It provides me the compressed versions but I would like to do this automatically.I don't want to deal with 2 files every time I want to edit something. 它为我提供了压缩版本,但我想自动执行。我不想每次想编辑东西时都处理2个文件。 So basically, I want to have 2 files in a folder, for instance, style.src.css and style.css . 所以基本上,我想在一个文件夹中拥有2个文件,例如style.src.cssstyle.css

I want to know how to do the following: 我想知道如何执行以下操作:

  1. Update the ouput file everytime I edit the input file. 每次我编辑输入文件时更新输出文件。
  2. A command that automatically compress CSS, Html, and Javascript files. 自动压缩CSS,HTML和Javascript文件的命令。

Thanks in advance. 提前致谢。

You should be able to have vim do that. 您应该能够让vim做到这一点。 A bit of reading on the vim autoscripts ( http://vimdoc.sourceforge.net/htmldoc/autocmd.html ) would be helpful, but here's a decent guess: 稍微阅读一下vim自动脚本( http://vimdoc.sourceforge.net/htmldoc/autocmd.html )可能会有所帮助,但这是一个不错的猜测:

au BufWritePost *.html !zip %.zip %

In .vimrc 在.vimrc中

YUI Compressor isn't VIM and is usually done manually, at build time, but you can instantiate YUI Compressor on-the-fly to handle minification on your server (requires Java). YUI Compressor不是VIM,通常是在构建时手动完成的,但是您可以即时实例化YUI Compressor以处理服务器上的缩小(需要Java)。

Note that YUI Compressor minifies JS and CSS (not HTML). 请注意,YUI Compressor会缩小 JS和CSS(而非HTML)。 Compression can also be done on the server, reducing file sizes even more. 压缩也可以在服务器上完成,从而进一步减小文件大小。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM