Giter VIP home page Giter VIP logo

typescript-react-loadable-server-rendering's Introduction

TypeScript, Code splitting and Server rendering

A React example project to demonstrate how to achieve code splitting plus server rendering using TypeScript ๐Ÿ˜๐Ÿ˜๐Ÿ˜.

Its main goals are:

  • Implement React code splitting
  • Implement React server rendering
  • Use Redux with server rendering
  • Use React Router in both case
  • Build all this features

And the last but not the least, this project demonstrate and explain how to make compatible and take advantage of TypeScript in all this features ๐Ÿ’ช.

Quick Start

Install
npm install

Build
npm run build-dev

Run
npm run serve

Built on top

This project implements the minimal requirement to demonstrate its purpose.

  • TypeScript v2.8

Universal

  • React v16.3
  • React Loadable v5
  • React Redux v5
  • React Router v4

Server

  • Express v4
  • Express es6 template engine

Build tools

Code

Source code is under source folder.

Server code is built into server folder.

Client code is built into client folder.

Build process

Both Client and Server application are built through Webpack.

Code splitting is made possible using React Loadable and Webpack dynamic imports.

Server rendering is dependent on build step below.

TypeScript type check and emit JavaScript es2015 (TypeScript without types) consumable by Babel.

babel-preset-react transform React jsx and babel-preset-env es2015 syntax into code understandable by the browser.

Babel apply plugins to make code splitting compatible with server rendering:

On server build dynamic-import-node transpile import() to a deferred require() for node.

On client build syntax-dynamic-import allow babel to parse dynamic import syntax but not transform it. Then Webpack split code via dynamic import.

On both build react-loadable/babel declare wich modules are being loaded.

Documentation

This sample project was made according to these documentations.

Code Splitting

Server Rendering

typescript-react-loadable-server-rendering's People

Contributors

nicolashemonic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 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.