Build Status

TL;DR
Before you dive into anything, see for yourself how easy you can setup a full workflow framework for your development and deployment for your real world project.
Step 1: Clone this repo
git clone https://github.com/iroy2000/react-redux-boilerplate.git
cd react-redux-boilerplate
Step 2: Install
Step 3: Start
And Done, as easy as 123!!
Preface
React Redux Boilerplate is a full fledged PRODUCTION READY workflow boilerplate for building complex React / Redux application.
The technologies used in this workflow boilerplate shows case a subset of technologies we are currently using within our team ( we put this project in github mainly as recruiting purpose for our team ), and we are trying to give our candidates confidence that by working with us, they will be using decent technologies as well as staying relevant to the industry. And that is what our team strongly believed in - technology innovation and promoting developers' relevancy in the industry.
If you are interested in working with us, feel free to send a message to iroy2000.
Note: This boilerplate is not to show case how to code in React / Redux, it is a boilerplate that hook everything up for you to develop a complex React / Redux project. And if you just want to learn React, we don't have complicated code example here and this boilerplate might be too complicated for your need.

React Redux Boilerplate
React Redux Boilerplate is a workflow boilerplate that make life easier for developers by providing a virtual development environment and production ready build process framework out of the box.
React Redux Boilerplate is for developing React client side application. So, if you are looking for:
Isomorphic (Universal) support, feel free to add server side support to it, or you can use something like Next.js, react-server or electrode
Features / Benefits
Features
- React 16.6
- Redux
- Saga
- ES6 / ES7
- ImmutableJS
- PreCSS ( supports SASS-like markup in your CSS )
- PostCSS ( with CSS modules activated by default )
- Webpack 4
- Reselect
- Lazy Loading component supports
- Type Checking with Babel Type Check ( Flow syntax )
- ESLint for syntax check
- Jest and Enzyme for Unit testing
Workflow
- Development
- Hot Module Reload during development
- Built-in lightweight config system
- Built-in fancy cli dashboard for reporting run time compile status
- Built-in support for multiple device concurrent debugging
- Build / Production
- Production bundle analyzing capability
- CSS / HTML / JS minification / Image optimization when built
- JS code duplication removal during built ( tree shaking capability )
- Deployment
- Built-in git commit hook, helpful for CI/CD process
- Built-in process to deploy files directly to S3 ( optional )
- Productivity
- Highly configurable build and workflow system ( webpack )
- Minimal setup time and allow you to invest into things that matters
- Everything automatic, you just care about development, nothing else \o/ Yeah ?!
If you are interested, please read the package.json for all installed modules and plugins.
Table of Contents
Basic
- Installation
- Initialize your project
- Suggested Workflow
- Folder Structure
- Production Readiness
- Configuration
- Port Configuration
- Installing Dependencies
Advanced
- Lazy Loading Component
- Writing Unit Test
- Configure git commit hook
- Multiple Device Concurrent Debugging
- Developing Template
- Production Optimization and Bundle Analysis
- Integration Note
- QA
Other
- Knowledge Base Reading
- How to Contribute
- Updates
Basic
Installation
Prerequisite
You need to have Node.js installed.
Instruction for installing NodeJS in Mac
Instruction for installing NodeJS in Window
Post Installation
If you would like to have Redux debug capabilities, you can download this Chrome extension Redux DevTool

Initialize your project
Now run the following commands in your terminal
NOTE: You only need to run this once!
$ npm install # This will install the necessary packages to use the app
That's it!
To run the app in Development Mode
Wait about 30 seconds for your development environment to initialize.
When it finishes, open your browser and go to http://localhost:8080/
If you see the landing page, it means you have set up everything successfully.
List of NPM Commands
$ npm run dev # build and watch, but javascript not minified
$ npm run build # build a minified production version
$ npm run lint # linting using ESLint
$ npm run test # run test using Jest
$ npm run clean # it runs before each build, so you don't need to
Suggested Workflow
After you check out the repo, I will usually do the following :
- Go to your project root in your host machine ( e.g. your Mac )
- Run
npm run dev in your terminal ( wait until the dashboard show complete status )
- Go to your browser and go to
localhost:8080
- Make code changes
- If there are compilation errors, you will see it in the terminal dashboard
- Watch your code changes reflect on browser without refreshing
- Repeat your development steps
That's very easy, isn't it?
Folder Structure
The entry point of your application is src/js/routes, it's basically a mapping between your views to a route.
All your javascript code lives in folder src/js
-- src/
-- js/
-- common/
-- api/ --> all api requests
-- components/ --> all share components
-- types/ --> all flow types
-- redux/
-- modules/ --> all redux code
-- saga/ --> all redux-saga code
-- selectors/ --> all reselect code
-- utility/ --> all non JSX utility
-- views/ --> all JSX code hook up with Route ( HoC ) or page specific components
-- style/ --> all global styles, layout, config
-- assets/ --> all static assets ( image, fonts ... etc )
-- template/ --> you probably won't touch this unless you want to create new template
-
For config/ and bin/ folder, it is covered at Configuration section
-
For __tests__/ folder, it is covered at Writing Unit Test section
-
For our Redux coding style, we are using Ducks standards
-
For how to write code in ES6 /React / Redux / POSTCSS ... etc, please feel free to look at our simple example code. And if you have question or want to study future, please checkout the Knowledge Base Reading section, which covers everything we used in this boilerplate.
NOTE: When you import resources, please make sure you have the right path
Production Readiness
React Redux Boilerplate supports production preview, which means that you can run the production build job and see how it looks like in production.
- Run
npm run build and wait until it is done
- Go to the project
docroot, you will see a index.html (template is customizable, please read Developing Template section)
- Open that
index.html in your browser, and that is the build version that just got generated
That's very easy, isn't it?
Difference between npm run dev v.s. npm run build
npn run dev is best to do JS / CSS only changes, and it comes with live reload functionality
npm run build is for testing what happen if your frontend assets are optimized ( production level code )
Please let me know if you have better work flow suggestion!!
Configuration
React Redux Boilerplate has two configuration strategies, one is for normal configuration, the other one is for sensitive information that you don't want others to know.
Configuring application
If you look at folder config, there are four files
default.json - all default configuration
development.json - when you run npm run dev, it will pull configuration from that file
release.json - when you run npm run build:release, it will use this configuration
production.json - when you run npm run build, it will use this configuration
We are using node-config, they have a pretty easy to understand documentation.
And in your config file ( json config file ), whatever you put inside the app, it will be injected into the client application and you can access to your app config data by using __CONFIG__ variables.
Let's say you have a config like the following
{
"app": {
"apiURL": "http://foo.bar/"
}
}
In your React application, you can access this variables
Note: If you want to add new npm target ( e.g. npm run build:stage ), you need to do the following :-
- Add a
stage.json file inside config folder
- Add
npm run build:stage ( or similar ) at package.json scripts section
- Add actual command mapping at
bin/commands.js
Configuring secret key/value pair
There are times you may want to put in secret information you don't want to check into the source code. In this boilerplate, you just need to create a file called .env in your PROJECT_ROOT, and you can put your secret over there ( we have put that into .gitignore just in case ). For example, in order to use the feature to deploy to S3, you need to provide the following information.
AWS_ACCESS_KEY=YOUR_AWS_ACCESS_KEY
AWS_SECRET_KEY=YOUR_AWS_SECRET_KEY
AWS_BUCKET=YOUR_AWS_BUCKET
AWS_CDN_URL=YOUR_AWS_CDN_URL
And your in node application or webpack config, those key/value pair will inject into process.env ( e.g. process.env.AWS_ACCESS_KEY ).
Note: Using .env file is optional, it meant to keep secret and inject information into environment variables, if you are using Jenkin or alike type of tools, you can inject environment variables there.