[DEPCREATED] Now I would recommend: For Server-side Rendering can use Next.js; For Client-side Rendering can use Create-React-App.
A starter kit for universal react app, this project is extends from ejected create-react-app.
- feature/without-immutablejs — rewrite redux code without immutablejs library
The motivation is simple, Best Development Experience and App performance.
When you start a new react project, you need to do a lot of settings:
reduxstore and middlewares as the state management.webpackconfig for development and production.- Enable Hot-reload.
- Configure
babel,eslint,jestand more... - If project gets bigger, you need to setup some plugins such as
happypack,webpack-dll-pluginto reduce webpack build time.
And once app is online, you have to optimize the performance for production.
All of the settings are very complicated, and if you want to go server-side rendering, it will be more complicated.
So I created this project and covers all the above settings, let you can focus on writing components, handling data flow and business logic.
reactas the view.react-routerv4 as the router.react-loadableprovides component based code splittingreact-helmetprovides control of the page head from within components.reduxas the state management container.redux-sagadeal with asynchronous action flow.react-router-reduxsync your router with redux statereselectto avoid frequent re-render that improve performance.styled-componentshelps you organize CSS in react project.font-awesomeas the Iconsbabelv7 for es6+ support and load babel-polyfill on-demand.isomorphic-fetchfor http request.
webpackv4 for both development and production bundles.webpack-DLL-plugin,cache-loader,happypackfor faster rebuild time.react-hot-loaderenable hot-reload both client and server-side.redux-devtoolsfor state history, playback, enable Time travel (you can also use redux-devtools-extension instead).webpack-bundle-analyzerto review webpack output files with an interactive zoomable treemap.ESLintmaintain your code quality with ease.Prettierkeep code style consistency, it will performing code formatting when commit.
You can also install react-devtools, this is a browser extension made by facebook.
- Route and component level code splitting.
- Async inject reducer and saga that are on the page.
- Offline support via service-worker.
- Long-term browser caching support.
- 🔥 Streaming Server-sdie rendering with
renderToNodeStreamintroduced inreact v16 - Server-side cache To speed up SSR.
This is a SSR (Server-side Rendering) project, so web content can be crawlable, and we use react-helmet to inject meta tags into html head dynamically from within components, so social medias like Google Plus and Facebook can know your website's metadata.
This project supports all of the ES6 and ES7 syntax features.
You can write css, less and scss, but I recommend you to use styled-components.
First, install the node modules
npm installor you can run yarn install
Then, run the following command, this will run the app in the development mode.
npm run devand you can open http://localhost:3000 to view it in the browser.
In the project directory, you can also run:
Generate a DLL file stored in build/dll folder, this file bundles all of the third-party packages like react, redux, styled-components etc, so we don't need rebuild these module in dev, it will save a lot of webpack rebuild time that increase development efficiency.
Generate stats.json and report.html in build folder, you can upload stats.json file on webpack.github.io/analyse/#hints or open report.html see bundle content.
Run the static type checker flow checkers to check your program.
Launches the test runner in the interactive watch mode.
Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
Run ESLint (code quality tool) that checks for problems in your app code.
Run your server with production build result.
src: Your app code.
src/containers: Routing components such as Login, Home pages...
src/copomnents: Shared specific styling components such as Button, Form...
src/client: client-side entry point
src/server: server-side entry point
config: Settings for project build.
scripts: CLI commands.
The data flow from server to client when received a http request, for more details you can see the code in src/server/server.js.
- Runs matching of routes in react-router for server.
- Extract all of the static preLoad methods from within components.
- Makes async data fetching request.
- Renders Route component to string.
- Get
styled-componentsstyle tags that are on page. - Get
react-loadablechunks that are on page. - Generate HTML string (with Meta, Script, Style tags) and send to client.
- Client-side receives html file with preload state from server.
- Client-side initializes redux store with given state and render page.
Since font-awesome v5 that give us a lot of benefits, we can inline the CSS directly into the page and load icon on-demand, you can add the icon you want.
- �In the
src/utils/font-awesome.js. - Import icon, ex:
import faUser from '@fortawesome/fontawesome-free-solid/faUser'. - Add icon into library.
fontawesome.library.add(faUser).
- Remove
Line 14insrc/client/index.js. - Remove
src/utils/font-awesome.js. - Remove all of the icons that used in React components.
- Remove
@fortawesome/fontawesome@fortawesome/fontawesome-free-brands@fortawesome/fontawesome-free-solidin thepackage.jsondependencies.
npm install bootstrap@v4.0.0 bootstrap-loader.- Set
process.env.SHOULD_USE_BOOTSTRAP=trueinconfig/webpack/index.js. - Bootstrap css and js will load into webpack bundle, now you can feel free to it.
- You can also install
reactstrap, its a bootstrap 4 components built forReact.
- Call API demo.
- Authentication Route.
- Load font-awesome 5 with inline style tag (like styled-components).
- Deploy a demo site.
- Rewrite homepage (I'm not good at UI design and I know it's ugly, can anyone give me some suggestions).
- Beauty terminal output.
- Modularized.
- Write unit test for react components, reducers and sagas.
This project is licensed under the MIT license, For more information see LICENSE.