This sample project illustrates a React/Redux application with optional server-side rendering bundled with Webpack.
- Server-Side Rendering in production mode (optional feature)
- Webpack 4
- Development mode: hot reload for React components, hot reload for Redux reducers and actions
- (optional) Code splitting
npm run dev
- wait for it to finish (it will say "Now go to http://127.0.0.1:3000" in the end)
- go to
- interact with the development version of the web application
Ctrl + C
npm run production
- wait for Webpack to finish the build (green stats will appear in the terminal, and it will print "Webpage rendering service is listening at port 3002" when the application has started)
- go to
- interact with the production version of the web application
- check out
./build/bundle-stats-2.htmlfor detailed info on which modules take up the most space in the output bundle
This application consists both of the "client side" and the "server side" (for illustration purposes).
./src/index.js) which is built by Webpack and run in a web browser, along with the "page rendering service" (
./rendering-service) which does the same thing but in a Node.js process on the server providing "Server-Side Rendering" capability.
The "server side" consists of the "API" (
./api) and the "proxy server" (
The "proxy server" approach illustrated in this app is for illustration purposes only. It is considered old-fashioned now as all modern applications are becoming more distributed and decentralized running API in a cloud (e.g. Amazon Lambda) and serving "statics" from a whole another place (e.g. Amazon S3, configured via
webpack.config.js) in which case the React application queries the API server by an absolute URL (this is called "CORS") and no proxying is needed, therefore the whole "proxy server" is moved out of the equation.
In this example though, for simplicity, "proxy server" is used and it runs on port
3000 and routes all relative URL paths to their destinations:
- "statics" ("static files", "assets") are served (in production mode only) on
/apiis proxied to the "API server" (running on port
- all the other URLs are proxied to the "page rendering service" (which runs on port
In development mode there's one more Node.js process running:
webpack-dev-server successor) is running on port
3001 which serves the "assets" compiled by Webpack (live) via HTTP protocol. In production there's no
webpack-serve and Webpack just outputs those compiled assets to the
./build folder and the "proxy server" serves those "assets" from there. In a real production environment though this "hand made" sample proxy server would have been dropped in favour of a proper proxy like NginX or HAProxy.