Skip to content

Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting

Notifications You must be signed in to change notification settings

MartinCerny-awin/isomorphic-react-redux-saga-ssr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OUTDATED PLEASE HAVE A LOOK FOR NEWER OPTIONS

⚡ Isomorphic JS - Server Side Rendering, Code Splitting and Hot Module Reloading ⚡

💭 What is it?

Isomorphic JS: - JavaScript that can run on both the server and client (or any other JS platform for that matter) !

Hot Module Reloading: - Replaces modules that have been changed in real time while preserving the state.

Server Side Rendering: - Renders Pages on the initial for fast page loads and search engine optimization

Code Splitting: - Split code into bundles so that code is asynchronously loaded by the client.

The code is influenced by https://medium.com/@apostolos/server-side-rendering-code-splitting-and-hot-reloading-with-react-router-v4-87239cfc172c

⚙ How?

The Basic setup goes like this...

An express server handles a request, renders the that page on the server and sends it back to the client. The code is bundled into chunks on build time which are requested by the client when needed for that route.

When in development mode the express server handles a request and uses the webpack.config.development.js configuration as middleware to listen for file changes, build then and push them to the client.


⚙ Technologies

React

v 15.5.0 version is used in this project with PropTypes being inside its own library. The React code is using ES6 and dividing components into presentation components and container components.

Redux

Reducers, actions creators and action types are using customized duck structure. They are stored inside JavaScript file in modules folder .

React Router 4

The React Router 4 routes are just components, which define the composition of UI.

Webpack 2

Used for code splitting.

Hot Module Loader 3

Replace changed modules in the real time. React Hot Loader 3 is in beta, but fixes several issues and is needed in case React Router 4 is used. This projects does HMR of Components, Containers, Styles, Sagas and Reducers

Babel

Compiler that helps us to write ES6 JavaScript. React ES6 features such property initializers, arrow functions and spread attribute are used in the project. React on ES6+

Express

Manages initial render of the content (SSR)

webpack-dev-middleware

Middleware which can be mounted in an express server to serve the latest compilation of your bundle during development. This uses webpack's Node API in watch mode and instead of outputting to the file system it outputs to memory.

webpack-hot-middleware

Alternative to webpack-dev-server but instead of starting a server itself it allows you to mount it in an existing / custom express server alongside webpack-dev-middleware.

Redux Saga

The implementation of Redux Saga was made with the help of Universal React Saga. The axios library was replaced by fetch and sagas fitting into modules were moved there.

Good article https://wecodetheweb.com/2016/10/01/handling-async-in-redux-with-sagas/

🛠 Setup

First install the dependencies, in the root directory of this project run. npm install

🤖 Running

For Development run npm run development

This will start a development server on localhost:8080 that utilizes hot module reloading for both React components and redux reducers.

For Production run npm run build && npm run production.

This will build all your assets and write them to a /build file in the root directory of this project. The script will then start up a express server on localhost:8080 that will utilize server side rendering and route based code splitting.

hmr-ssr

🗒 Notes

Hot Module Reloading does not work with System.import, as such there are two route sources.

  • The first one src/universal/routes/sync.js is for static routes (no code splitting) that is for the development environment to work nicely with React Hot Loader 3
  • The second route source src/universal/routes/async.jsx is for asynchronous routes (Code splitting using System.import).