Giter VIP home page Giter VIP logo

123456's Introduction

React Server Side Rendering Boilerplate โš›๏ธ๐ŸŽจ

Tools like create-react-app have made setting up client-side React apps trivial, but transitioning to SSR is still kind of a pain in the ass. The Razzle tool looks like an absolute beast, but sometimes you just want to see the whole picture. This is a sample setup for full-featured, server-rendered React applications.

What's included:

  • Server-side rendering (via the excellent React Loadable package)
  • Redux (with server-side data fetching/store population)
  • React Router v4
  • Code splitting
  • Webpack 4
  • React Helmet for dynamic manipulation of the document <head />
  • Dev server with hot-reloading
  • Jest and Enzyme config ready to test the crap out of some stuff
  • CSS Modules, Sass, and autoprefixer
  • Run-time environment variables
  • Node.js clusters for improved performance under load (in production)
  • Prettier and ESLint run on commit
  • Docker-ized for production like a bawsss

Initial setup

  • cp .env_SAMPLE .env
  • npm install

Development

Production

  • npm run build && npm run start-prod
    • Bundle the JS and fire up the Express server for production
  • npm run docker (debugging production)
    • Build and start a Docker image in production mode (mostly useful for debugging)

Current Quirks

  • This app does not create a server bundle via webpack, which means some of the crazy things you can do with webpack (importing images, for example) are not possible here without getting dirty.
  • CSS modules are not enabled for files inside src/styles -- use this directory for global styles instead. This is configured in the webpack config files, so start there if you'd like to change anything.
  • Routing configuration can potentially be slightly duplicated. All routes should be defined in their normal React Router v4 fashion. However, any routes that need to have data fetched before rendering (on the server) need some extra configuration inside sever/fetchDataForRender (in the ROUTES_THAT_FETCH_DATA array).

cj-scripts

If you're interested in creating your own react-scripts-eque CLI that wraps up some of the concepts in this project take a look at my cj-scripts repo.

123456's People

Contributors

cullenjett avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.