[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:
redux
store and middlewares as the state management.webpack
config for development and production.- Enable Hot-reload.
- Configure
babel
,eslint
,jest
and more... - If project gets bigger, you need to setup some plugins such as
happypack
,webpack-dll-plugin
to 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.
react
as the view.react-router
v4 as the router.react-loadable
provides component based code splittingreact-helmet
provides control of the page head from within components.redux
as the state management container.redux-saga
deal with asynchronous action flow.react-router-redux
sync your router with redux statereselect
to avoid frequent re-render that improve performance.styled-components
helps you organize CSS in react project.font-awesome
as the Iconsbabel
v7 for es6+ support and load babel-polyfill on-demand.isomorphic-fetch
for http request.
webpack
v4 for both development and production bundles.webpack-DLL-plugin
,cache-loader
,happypack
for faster rebuild time.react-hot-loader
enable hot-reload both client and server-side.redux-devtools
for state history, playback, enable Time travel (you can also use redux-devtools-extension instead).webpack-bundle-analyzer
to review webpack output files with an interactive zoomable treemap.ESLint
maintain your code quality with ease.Prettier
keep 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
renderToNodeStream
introduced 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 install
or you can run yarn install
Then, run the following command, this will run the app in the development mode.
npm run dev
and 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-components
style tags that are on page. - Get
react-loadable
chunks 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 14
insrc/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-solid
in thepackage.json
dependencies.
npm install bootstrap@v4.0.0 bootstrap-loader
.- Set
process.env.SHOULD_USE_BOOTSTRAP=true
inconfig/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
.