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.

  • Deploying with github, git_discovery_across_filesystem not set
  • Error on first git aws.push to elastic beanstalk
  • deploy nodejs to heroku
  • Git clone over an existing non-git project
  • Git Push to Amazon S3 for Deploying Assets?
  • Git deployment rollback workflow
  • 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?

  • Where is Visual Studio storing Publish Profiles?
  • Deploy specific features from the master branch
  • GIT How to clean history pack for old deleted files?
  • Error pushing to GitHub using Git for Windows
  • git add all .tex files recursively
  • Git refuses to push after restart
  • 3 Solutions collect form web for “Compress JS/CSS files on deploy using Git”

    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

    Git Baby is a git and github fan, let's start git clone.