Skip to content

Commit 9aa89ff

Browse files
committed
updated README.MD
1 parent 8e4fa3d commit 9aa89ff

File tree

1 file changed

+21
-44
lines changed

1 file changed

+21
-44
lines changed

README.MD

Lines changed: 21 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
# Behold the React + Express + Webpack + Babel Boilerplate
2-
## Server-side rendering and Redux is now included!
1+
# Behold the ReactJS + ExpressJS Boilerplate
2+
## With Server-side rendering, Redux and React-router v4
33

4-
This is a boilerplate to use ReactJS ExpressJS and Redux in a project.
4+
This is a boilerplate to use ReactJS, ExpressJS, Redux and React Router v4 in a project.
55

66
- [ReactJS] - The state based framework for your Views
7+
- [React Router v4] - For routing to different paths
78
- [Redux] - Redux manages your state
89
- [Babel] - The compiler to compile your JS files with es6, es7, JSX syntax to regular javascript
910
- [Webpack] - The module binder which takes all your JS files from different directories and compiles them into a single app.bundle.js (you can change the filename of course) so you can include it in a HTML page
@@ -12,70 +13,46 @@ This is a boilerplate to use ReactJS ExpressJS and Redux in a project.
1213

1314
# Installation
1415

15-
Node Version: v7.2.1
16+
Node Version: v8.3.0
1617

1718
Just clone this repo or download the zip file. `cd` into the directory and run
1819

1920
npm install
2021

21-
To use webpack you also need to run
22+
## Developing App with [Hot Reload]
23+
To develop your own react application, you can take advantage of React Hot Loader and Webpack Dev Server. To develop app with hot reload:
2224

23-
npm install webpack -g
25+
npm run dev
2426

25-
You might need to run this command as `sudo`.
27+
Now you can access your react application on http://localhost:8080
2628

27-
Once you have the webpack installed, cd into the directory where you cloned this repo and run
29+
## Production build and Deploy
30+
To make a production build of your project, run the following commands
2831

29-
webpack
32+
npm run build
33+
34+
This will create create two files: `index.js` in `server/public/js` and `server.js` in `server/bin`.
3035

31-
Note: if you would rather not install webpack globally, you can also run webpack locally:
32-
33-
node_modules/.bin/webpack
34-
35-
This will create update two files: `server.bundle.js` and `bin/app.bundle.js`.
36-
37-
`server.bundle.js` will be used for serving the application on port 3000 and `app.bundle.js` is the actual react app itself.
36+
`server.js` will be used for serving the application on port 3000 and `index.js` is the actual react app itself.
3837

3938
Finally run
4039

4140
npm start
4241

4342
The you will be able to access this app from http://localhost:3000.
4443

45-
# Flow of the app/what is going on
46-
So here is the flow.
47-
48-
First you create all your ReactJS files using whatever syntax you like. These files will stay in the `views` directory. If you are using Redux then you'll be using all the directories but if you don't know Redux you can just remove the `actions`, `containers` and `reducers` directories. You can use plain JSX or ES6 or Experimental ES7 in your JS files.
49-
50-
Once you've done that you fire up a terminal in that directory and run webpack. This has two steps:
51-
52-
- Webpack calls babel to compile all the files in the views directory to standard javascript, because current browsers doesn't understand ES6/ES7/JSX syntax.
53-
- Once the compiling is done webpack takes all the compiled files and binds then into `app.bundle.js` and `server.bundle.js` along with all the dependencies.
54-
55-
So now you have a file in your `bin` directory which is `app.bundle.js`. This is basically your whole React app in one file. And you also have a file `server.bundle.js` which your ExpressJS server.
56-
57-
### Serve your app with server side rendering (and why it is important)
58-
59-
To serve your app with server side rendering, all you need to do is run `npm start`. The way it works is that the ExpressJS server (`server.js`) renders the app on the server and serves it to the public.
60-
61-
I know it's confusing. Hold on!
62-
63-
When the React app is served without server side rendering, a browser will download the `index.html` and load the `app.bundle.js` in real time. When the `app.bundle.js` has finished loading up it will render the page the way you have programmed. This initial render takes longer than usual and can be a nightmare for SEO or search engines. Also, a big reason of using React is how fast it is right?!
64-
65-
With server side rendering, the ExpressJS server will use the React engine to take your `app.bundle.js` and render the necessary parts of your webpage to plain HTML string. So the client/public will receive the same `index.html` with `app.bundle.js` included with it, but this time the rendering is already completed by the server. Your `app.bundle.js` won't modify or change anything in the page unless you have clicked something on the page.
44+
To get a distributable tarball of your application, run this command
6645

67-
To understand how this server side rendering is done, you need do some research on the following resources:
46+
npm pack
6847

69-
- [ReactDOMServer]
70-
- [Redux Server Side]
71-
- [React Router Server Side]
48+
Remember that you have to run `npm run build` before doing this. This will create a tar.gz file in your root folder. The contents in this file is deployable. All you need to do is copy the contents inside package folder inside this tar.gz file to your server and run the app with something like [pm2].
7249

7350

7451
[ReactJS]: <https://facebook.github.io/react/>
7552
[Babel]: <https://babeljs.io/>
7653
[Webpack]: <https://webpack.github.io/>
54+
[React Router v4]: <https://reacttraining.com/react-router/>
55+
[Hot Reload]: <https://stackoverflow.com/questions/41428954>
7756
[ExpressJS]: <http://expressjs.com/>
7857
[Redux]: <http://redux.js.org/>
79-
[ReactDOMServer]: <https://facebook.github.io/react/docs/react-dom-server.html>
80-
[Redux Server Side]: <http://redux.js.org/docs/recipes/ServerRendering.html>
81-
[React Router Server Side]: <https://github.com/ReactTraining/react-router/blob/master/docs/guides/ServerRendering.md>
58+
[pm2]: <https://github.com/Unitech/pm2>

0 commit comments

Comments
 (0)