Minify JavaScript during GitHub Pages build?
The GitHub pages build service cannot have any other code running on it other than Jekyll in safe mode and the small number of included plugins. This is done for security.
Your best option is to use an alternative service to build your site and push the result back to GitHub. The source for the site would reside in the master branch and the compiled source in gh-pages.
A suitable service for doing so would be one of many CI services, such as Travis CI. These are typically used to run software test suites on every push to a repo, but can be used to build your website and push the result back to you.
The Jekyll docs have a guide for testing builds on Travis. Pushing the output isn't mentioned. You'll need a script in the after_success
derivative in the Travis conf file. An example from a site I maintain.
To authenticate your push the script will need access to your github personal access token. You can't just put this straight in the deploy script as it's a secret. See the Travis docs on encrypting environment variables.
If you are using Github to generate the site and display it, there is no option to do this because Github is strict about what it will process - for security.
A workaround is to do your compiling and processing locally, then push the resulting output to to gh-pages - which is happy to simply host static pages.
You can still use github to host the project. You just do not use Github to compile it.
Your dev process might be:
- Check you're master and local match.
- Do your work in dev mode.
- Build in production.
- Use grunt or other program to minify/uglify/etc the _site production files - outputting to a separate dist (distribution) folder.
- Push the contents of the dist folder to your gh-pages.
- Commit changes to the project files back to the master.
I am probably not making much sense, but perhaps this discussion might help more: https://gist.github.com/cobyism/4730490
Have fun!