使用Git在部署上压缩JS / CSS文件 [英] Compress JS/CSS files on deploy using Git
问题描述
我对git有点新鲜感。另外,这是我第一个自动化部署过程的项目。到目前为止,能够执行 git push dev
并且上传文件,复制配置文件等是幸福的。
<现在我想在推送到我的开发服务器时缩小JS / CSS文件。我正在考虑在服务器上安装一些命令行工具,以便在特定文件夹中对每个js / css文件进行缩小和压缩,并保存到post-receive git钩子中。
这是一个好方法吗? (因为我已经阅读过有关将压缩文件添加到回购和其他想法的信息,我不觉得相信)。如果是这样,哪些工具最适合该任务? nofollow> http://git-scm.com/book/ch7-2.html
我认为你会从不在服务器上进行提交,即服务器将仅用于 结帐更新的主设备,并且不会更新它。这个技巧会在结账时自动缩小任何* .css文件:
#在回购中
$ echo'* .css filter = minify'>> .git / info / attributes
$ git config filter.minify.clean cat
$ git config filter.minify.smudge minify-command
其中minify-command应该是缩小* .css文件的命令,即
$ cat foo.css | minify-command> foo-minified.css
是否接近您想要的?
I'm kinda new to git. Also, this is my first project where I'm automating the deployment process. So far it's been bliss to being able to do git push dev
and have files uploaded, config files copied, etc.
Now I want to minify JS/CSS files when I push to my dev server. I was thinking of installing some command-line tool on the server for minifying and for-each js/css file on certain folder, compress and save, on a post-receive git hook.
Is this a good approach? (cause I've read about adding compressed files to the repo and other ideas I don't feel quite convinced)
If so, which tools are best for the task?
http://git-scm.com/book/ch7-2.html
I assume that you will never make a commit on server i.e. server will be used to only checkout updated master and never update it. This trick will automatically minify any *.css files on checkout:
# within repo
$ echo '*.css filter=minify' >> .git/info/attributes
$ git config filter.minify.clean cat
$ git config filter.minify.smudge minify-command
Where the minify-command should be the command that minifies *.css files i.e.
$ cat foo.css | minify-command > foo-minified.css
Is it close to what you want?
这篇关于使用Git在部署上压缩JS / CSS文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!