Table of Contents
- Running the Project
- Project Structure
- Live Development
- Building for Production
- Thank You
When that's done, install the project dependencies. It is recommended that you use Yarn for deterministic dependency management, but
npm install will suffice.
$ yarn # Install project dependencies (or `npm install`)
Running the Project
After completing the installation step, you're ready to start the project!
$ yarn start # Start the development server (or `npm start`)
While developing, you will probably rely mostly on
yarn start; however, there are additional scripts at your disposal:
||Serves your app at
||Builds the application to ./dist|
||Runs unit tests with Karma. See testing|
||Lints the project for potential errors|
||Lints the project and fixes all correctable errors|
The project structure presented in this boilerplate is fractal, where functionality is grouped primarily by feature rather than file type. This structure is only meant to serve as a guide, it is by no means prescriptive. That said, it aims to represent generally accepted guidelines and patterns for building scalable applications. If you wish to read more about this pattern, please check out this awesome writeup by Justin Greenberg.
. ├── build # All build-related code ├── public # Static public assets (not imported anywhere in source code) ├── server # Express application that provides webpack middleware │ └── main.js # Server application entry point ├── src # Application source code │ ├── index.html # Main HTML page container for app │ ├── main.js # Application bootstrap and rendering │ ├── normalize.js # Browser normalization and polyfills │ ├── components # Global Reusable Components │ ├── containers # Global Reusable Container Components │ ├── layouts # Components that dictate major page structure │ │ └── PageLayout # Global application layout in which to render routes │ ├── routes # Main route definitions and async split points │ │ ├── index.js # Bootstrap main application routes with store │ │ ├── Home # Fractal route │ │ │ ├── index.js # Route definitions and async split points │ │ │ ├── assets # Assets required to render components │ │ │ ├── components # Presentational React Components │ │ │ └── routes ** # Fractal sub-routes (** optional) │ │ └── Counter # Fractal route │ │ ├── index.js # Counter route definition │ │ ├── container # Connect components to actions and store │ │ ├── modules # Collections of reducers/constants/actions │ │ └── routes ** # Fractal sub-routes (** optional) │ ├── store # Redux-specific pieces │ │ ├── createStore.js # Create and instrument redux store │ │ └── root.reducers.js # Reducer registry and injection │ └── styles # Application-wide styles (generally settings) └── tests # Unit tests
Hot reloading is enabled by default when the application is running in development mode (
yarn start). This feature is implemented with webpack's Hot Module Replacement capabilities, where code updates can be injected to the application while it's running, no full reload required. Here's how it works:
For Sass, any change will update the styles in realtime, no additional configuration or reload needed.
We recommend using the Redux DevTools Chrome Extension. Using the chrome extension allows your monitors to run on a separate thread and affords better performance and functionality. It comes with several of the most popular monitors, is easy to configure, filters actions, and doesn't require installing any packages in your project.
However, it's easy to bundle these developer tools locally should you choose to do so. First, grab the packages from npm:
yarn add --dev redux-devtools redux-devtools-log-monitor redux-devtools-dock-monitor
Then follow the manual integration walkthrough.
To add a unit test, create a
.spec.js file anywhere inside of
./tests. Karma and webpack will automatically find these files, and Mocha and Chai will be available within your test without the need to import them. Here are a few important plugins and packages available to you during testing:
- If you mistype a property name (e.g.
expect(false).to.be.tru) then the expression evaluates to undefined, the magical getter on the
trueis never run, and so your test silently passes.
- By default, linters don't understand them and therefore mark them as unused expressions, which can be annoying.
Dirty Chai fixes this by converting these getters into callable functions. This way, if mistype an assertion, our attempt to invoke it will throw due to the property being undefined.
// This silently passes because the getter on `true` is never invoked!// Much better! Our assertion is invalid, so it throws rather than implicitly passing.
Building for Production
Out of the box, this starter kit is deployable by serving the
./dist folder generated by
yarn build. This project does not concern itself with the details of server-side rendering or API structure, since that demands a more opinionated structure that makes it difficult to extend the starter kit. The simplest deployment strategy is a static deployment.
Serve the application with a web server such as nginx by pointing it at your
./dist folder. Make sure to direct incoming route requests to the root
./dist/index.html file so that the client application will be loaded; react-router will take care of the rest. If you are unsure of how to do this, you might find this documentation helpful. The Express server that comes with the starter kit is able to be extended to serve as an API and more, but is not required for a static deployment.