chikara-chan / react-isomorphic-boilerplate

🌟 An universal React isomorphic boilerplate for building server-side render web app.
https://chikara-chan.github.io/react-isomorphic-boilerplate/
MIT License
652 stars 148 forks source link
babel boilerplate eslint isomorphic koa2 react redux server-side-rendering webpack

React Isomorphic Boilerplate

An universal React isomorphic boilerplate for building server-side render web app.

dependencies Status devDependencies Status PRs Welcome npm

Introduction

This repository is an universal React isomorphic boilerplate for developer to quickly build a super fast and powerful web app that can be rendered both on the client and on the server using the most cutting-edge technology. Compared to others, this boilerplate has more pithily and more elegant configuration file based on environment variables, one for development, one for production. In addition, the directory structure is organized corresponding to mvc principle aim at the best practice.

Technology Stack

Getting Started

What's included

react-isomorphic-boilerplate/                // root directory
β”œβ”€β”€ build/                                   // webpack config directory
β”‚     β”œβ”€β”€ webpack.dev.config.js                 // config for webpack when run development bundle
β”‚     └── webpack.prod.config.js                // config for webpack when run production bundle
β”œβ”€β”€ client/                                  // client directory
β”‚     β”œβ”€β”€ about/                                // `about` module
β”‚     β”œβ”€β”€ common/                               // `common` module
β”‚     β”œβ”€β”€ home/                                 // `home` module
β”‚     β”œβ”€β”€ shared/                               // shared module
β”‚     β”œβ”€β”€ explore/                              // `explore` module
β”‚     β”œβ”€β”€ index.js                              // client entry file
β”‚     └── routes.js                             // client route config
β”œβ”€β”€ dist/                                    // bundle output directory
β”‚     β”œβ”€β”€ client/                               // the client side output directory
β”‚     └── server/                               // the server side output directory
β”œβ”€β”€ server/                                  // server directory
β”‚     β”œβ”€β”€ controllers/                          // controllers in server
β”‚     β”œβ”€β”€ middlewares/                          // custom middlewares in server
β”‚     β”œβ”€β”€ models/                               // models in server
β”‚     β”œβ”€β”€ routes/                               // routes in server
β”‚     β”œβ”€β”€ app.js                                // create koa instance in server
β”‚     β”œβ”€β”€ server.dev.js                         // entry file in development mode
β”‚     └── server.prod.js                        // entry file in production mode
β”œβ”€β”€ views/                                   // views directory
β”‚     β”œβ”€β”€ dev/                                  // output files generated by tpl in development mode
β”‚     β”œβ”€β”€ prod/                                 // output files generated by tpl in production mode
β”‚     └── tpl                                   // templates injected by html-webpack-plugin
β”œβ”€β”€ .editorconfig                            // uniform the text editor behavior
β”œβ”€β”€ .eslintignore                            // which paths should be omitted from linting
β”œβ”€β”€ .eslintrc.json                           // specific rules for eslint
β”œβ”€β”€ .gitattributes                           // uniform the new line perform behavior
β”œβ”€β”€ .gitignore                               // ignore the specific files when using git
β”œβ”€β”€ LICENSE                                  // license information
β”œβ”€β”€ package.json                             // npm entry file
β”œβ”€β”€ README.md                                // just what you see now
└── yarn.lock                                // lock file autogenerated by yarn

Why Isomorphic

SEO

An application that can only run in the client-side cannot serve HTML to crawlers, so it will have poor SEO by default. Web crawlers function by making a request to a web server and interpreting the result. but if the server returns a blank page, it’s not of much value. There are workarounds, but not without jumping through some hoops.

Performance

By the same token, if the server doesn’t render a full page of HTML but instead waits for client-side JavaScript to do so, users will experience a few critical seconds of blank page or loading spinner before seeing the content on the page. There are plenty of studies showing the drastic effect a slow site has on users, and thus revenue.

Maintainability

While the ideal case can lead to a nice, clean separation of concerns, inevitably some bits of application logic or view logic end up duplicated between client and server, often in different languages. Common examples are date and currency formatting, form validations, and routing logic. This makes maintenance a nightmare, especially for more complex apps.

Problem exists yet

FOUC

It happens when run in development mode. This is caused by deprecated using extract-text-webpack-plugin in development for getting a seamless hmr experience.(Why deprecated? See this Issue) If you are not an OCD, go ahead, ignore it.

Mismatch

It happens also when run in development mode. This is caused by when you update the react component code and reload the page, the markup generated mismatches that on server render. However, once you restart the server, the checksum will be valid. So it is harmless, ignore it also.

Links

http://www.jianshu.com/p/0ecd727107bb

License

MIT