Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compress JS/CSS files on deploy using Git

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?

like image 970
Nacho Avatar asked Dec 03 '12 17:12

Nacho


1 Answers

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?

like image 120
the.malkolm Avatar answered Oct 17 '22 07:10

the.malkolm