Using React with Github Pages

Using React with Github Pages
0.0 0

#1

I want to use React with Github Pages, but i am not sure what is the best way to do this. I have been thinking about this and i think there are a few options:

  1. Use CDN to put link to react in the header of the page
  2. Use webpack to put React in the bundle.js file
  3. Download react and just include the files with the script tag (./react.js)

What do you guys think? What is the best way to use React with github pages? I will need to use webpack for my SASS and babel files so i might as well use it to put the React files inside also. I think this is the best way i can think of.


#2

Github pages just serves static files as far as I know, so no server side technologies like NodeJS for webpack.

You can, of course, setup webpack on your development machine, transpile everything and push the entire project to github to be served by Github pages.

Including React via bundling or CDN at that point is up to you. CDNs are pretty fast and in part work by maintaining caches on users machines. By transpiling React into your bundle you’ll force visitors who already have React cached to re-download it.

For a Github pages website I think the difference isn’t that big a deal anyway, whatever you prefer.


#3

I believe create-react-app has a readymade solution for building and then hosting to GitHub Pages very easily, however you can also simply run npm build from a create-react-app project and it will generate html, css, and js from your project which can be easily hosted to GitHub Pages assuming you have it set up, or elsewhere.


#4

I recommend checking out create-react-app and reading their very good documentation.


#5

Thanks all for the replies I will start building my app now :slight_smile: