Skip to content

Instantly share code, notes, and snippets.

@rhewitt22
Created January 12, 2016 15:24
Show Gist options
  • Save rhewitt22/2ece6639313b7438ec9b to your computer and use it in GitHub Desktop.
Save rhewitt22/2ece6639313b7438ec9b to your computer and use it in GitHub Desktop.
Publish a demo to GitHub Pages

Publish a demo to GitHub pages

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment