Coder Social home page Coder Social logo

martincerny-awin / isomorphic-react-redux-saga-ssr Goto Github PK

View Code? Open in Web Editor NEW
18.0 1.0 5.0 74 KB

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

JavaScript 93.03% CSS 6.97%
isomorphic react redux redux-saga code-splitting hot-reloading react-router-v4 webpack2 hot-module-replacement server-side-rendering

isomorphic-react-redux-saga-ssr's Introduction

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).

isomorphic-react-redux-saga-ssr's People

Contributors

alex-ray avatar martincerny-awin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

isomorphic-react-redux-saga-ssr's Issues

Hot reload does not work for universal/modules/counter/components/Counter.css

Hi Martin,
Excellent work with this example.
It seems that the hot reload does not work for the css file.

[HMR]  - ./~/css-loader?{"root":"/home/pc/Documents/funspace/isomorphic-react-redux-saga-ssr/src","modules":true,"importLoaders":1,"localIdentName":"[name]_[local]_[hash:base64:5]"}!./src/universal/modules/counter/components/Counter.css

Can you please have a look please? I could not solve the issue.
I think I will use this boilerplate as a starter for a new project. Do you think it will change a lot to use React 16 with the hydrate function on client side?

Thanks

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.