Compress JS/CSS files on deploy using Git

我的梦境 提交于 2019-12-03 08:01:06

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?

By rewriting files on dev and not having the minified files in your local repo, the two repositories will always be out of sync with each other.

You might want to rethink the way you deploy your site to dev, instead of pushing to dev, you might want to pull on dev from a prestine repository for example.

Maybe you're looking for adding a post-checkout hook (or maybe it's another hook, according to your deploy system), and then launch with that the script which will minify your files.

You can also use the hook to check the modified date of the concerned files before doing that

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!