This project is a refactoring of the default app created by create-react-app v1.0.7, and then ejected.
A universal app runs both on the server and the client, and shares as much code as possible between the server and client - typically around 90%.
Development
Production
For a step by step explanation read the article https://medium.com/leanjs/universal-create-react-app-step-by-step-b80ba68d125d
yarn install
yarn start
to run it in developmentnpm run build
to build the production bundle. You must build the production bundle before running the production bundle.npm run serve
to run the production bundle.yarn start
), you can test the CSS hot reloading by changing this file /src/client/index.cssThe source code (src) is split in 3 folders:
The server is implemented using Express
There are two build scripts. One to build the JavaScript bundle that will be sent to the client. By default from the same server but you could serve it via a CDN or anywhere else. The other build script builds the JavaScript bundle that runs on the server.
The start script will try to run the client (Webpack Dev Server) on a given port (3000 by default). If the port is not available it will try to find another port. We have implemented the same on the port used to run the server. The start script will try to run the server (Express compiled with Webpack) on a given port (5678 by default). If the port is not available it will try to find another port.
For a step by step explanation read the article https://medium.com/leanjs/universal-create-react-app-step-by-step-b80ba68d125d
All the features that you have in create-react-app are included in this project, plus react-router v4.
yarn start
will start two servers. The first one (Webpack Dev Server), to build and serve the JavaScript bundle to the client. The Second one (Express), to render the app on the server.npm run serve
(note, you must first build the production bundle by executing npm run build
), the CSS will be displayed from the beginning. The reason for this is that we don't hot replace the CSS in production.Apollo GitHunt-React example was a great source of inspiration for finding solutions.
You can read here the original README.md generated by create-react-app in this repo https://github.com/facebookincubator/create-react-app/blob/v1.0.7/packages/react-scripts/template/README.md