Using Next.JS to build Static Dynamic Websites... and never pay for font-end hosting again!

173e23850a81c3f494ae957e1417c02d?s=47 Evan Tahler
September 12, 2019

Using Next.JS to build Static Dynamic Websites... and never pay for font-end hosting again!

Save 10s of dollars a month!

Next.js is a static & dynamic site rendering tool for websites based on React. We can use Next.js to flatten and build static sites for us using React. We can then upload these packs to Github Pages for a freely hosted website. This talk will focus less on the React part of things, and more on the "devops" tools we use to build and host the site - Next, Circle.CI, and Github Pages

Related Repository: https://github.com/evantahler/next-static-hosting

This is how we build www.actionherojs.com

173e23850a81c3f494ae957e1417c02d?s=128

Evan Tahler

September 12, 2019
Tweet

Transcript

  1. 1.

    Using Next.JS to build Static Dynamic Websites and never pay

    for hosting again! @evantahler https://github.com/evantahler/next-static-hosting
  2. 2.
  3. 3.
  4. 4.

    Goals • Use React to create our website ◦ A

    statically compiled front-end that still allows for dynamic content • Pay 0$ for hosting • HTTPS + Custom Domain* • Continuous deployment with a test suite ◦ Git push -> (wait) -> live site • Use a CDN to make things snappy around the world This is overkill for many sites, but free production-grade ops? Why not!
  5. 6.

    Tools This will be a “devops”-focused talk 1. Next.JS 2.

    Github 3. Circle.CI 4. Github Pages All Free for Open Source Projects + Students!
  6. 7.

    1. Next.JS • React + a sane router, webpack, server-side-rendering

    and all the annoying stuff handled for you • “Page” top-level components • `next dev` - hot reload when developing • `next build` - pre-compile pages for faster serving • `next export` - compile HTML, JS and CSS
  7. 8.
  8. 9.
  9. 10.

    2. Circle.CI Build Process triggered after every `git push` 1.

    “Build” 2. “Test” 3. “Deploy”
  10. 12.
  11. 13.
  12. 14.
  13. 15.

    3. Github Pages Free Hosting for static assets! 1. Almost

    no configuration 2. Domain Name Mapping via C-Names 3. Hosting for a chosen branch a. Usually called “gh-pages”
  14. 16.

    3. Github Pages - Gotchas We want to make a

    separate branch for hosting automagically - called gh-pages 1. “Read” Key vs “Write” Key - Github Access from Circle.CI 2. CNAME File - needs to be in your gh-pages branch 3. Tell Circle.CI not to test the gh-pages branch 4. Tell Github you don’t want to build a Jekyl site
  15. 17.

    Deploy Steps • NPM install • Next Build • Next

    Export • Copy to a new folder that maps to the gh-pages branch • Copy next export files + CNAME file • (force) push to gh-pages branch
  16. 18.
  17. 19.
  18. 21.