Most projects on GitHub have a .gitignore
file that prevents generated or distribution files from being checked into version control. This makes sense as they are completely dependent on the source files used to generate them.
If you have ever wanted to quickly post a demo of a project on GitHub using the free GitHub Pages service without commiting distribution files you're in luck.
If you use npm scripts as your build tool you can quickly publish a demo with one line using gh-pages
from npm.
// Install Dependencies
npm i --save-dev gh-pages
package.json
{
"scripts": {
"publish:demo": "gh-pages -d dist"
}
}
Assuming your distribution directory is called dist
then run npm run publish:demo
.
or if you have a complex build step in npm scripts already:
{
"scripts": {
"build": "A bunch of steps go here (scss -> css), (mangle js), etc",
"publish:demo": "npm run build && gh-pages -d dist"
}
}
Then run npm run publish:demo
to post your dist folder to the gh-pages branch. The &&
means that the publish step won't run unless the build is successful.