dhilt / react-try

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

React and Redux, Webpack 2 boilerplate

Table of contents

What is this?

Boilerplate I extracted from a small real world project.

Webpack 2 is still in beta, but at this point is the only version that I managed to run everything I wanted, including hot module replacement.

This boilerplate includes complete, minimal react app. By complete I mean it has examples for:

  • components (both container/views and regular ones)
  • routes
  • reducers (redux)
  • actions (both sync and async),
  • SASS (with autoprefixer)1
  • dummy API
  • using assets (in CSS and components)
  • imports relative to the app root

Example dashboard

1 Using source maps breaks urls in the CSS loader - webpack-contrib/css-loader#232. Try this to fix it (but it breaks testing from local network).

Features

  • React
  • React router
  • Redux
  • Redux Thunk
  • Redux DevTools (you need to have browser extension installed)
  • Immutable reducer data
  • Webpack 2 (development and production config)
  • Hot Module Replacement
  • Babel - static props, decorators
  • SASS with autoprefixing
  • Webpack dashboard
  • Linting
  • Included es6-promise and isomorphic-fetch
  • Preview production build
  • File imports relative to the app root
  • Git hooks - lint before push

TODO

  • Tree shaking build
  • Switch to redux-saga
  • Universal rendering
  • Server async data
  • Internationalization

Other nice to have features

  • Generating icon font from SVGs
  • Modernizr
  • Google analytics
  • Error reporting (not sure if this should be the part of the boilerplate)

Setup

Tested with node 6.x and 7.x

$ npm install

Running in dev mode

$ npm start

Visit http://localhost:3000/ from your browser of choice. Server is visible from the local network as well.

Running in the iTerm2

It is using webpack dashboard, so please note the following:

OS X Terminal.app users: Make sure that View → Allow Mouse Reporting is enabled, otherwise scrolling through logs and modules won't work. If your version of Terminal.app doesn't have this feature, you may want to check out an alternative such as iTerm2.

Build (production)

Build will be placed in the build folder.

$ npm run build

If your app is not running on the server root you should change publicPath at two places.

In webpack.config.js (ATM line 147):

output: {
  path: buildPath,
  publicPath: '/your-app/',
  filename: 'app-[hash].js',
},

and in source/js/routes (ATM line 9):

const publicPath = '/your-app/';

Don't forget the trailing slash (/). In development visit http://localhost:3000/your-app/.

Running in preview production mode

This command will start webpack dev server, but with NODE_ENV set to production. Everything will be minified and served. Hot reload will not work, so you need to refresh the page manually after changing the code.

npm run preview

Linting

For linting I'm using eslint-config-airbnb, but some options are overridden to my personal preferences.

$ npm run lint

Git hooks

Linting pre-push hook is not enabled by default. It will prevent the push if lint task fails, but you need to add it manually by running:

npm run hook-add

To remove it, run this task:

npm run hook-remove

Changelog

0.1.4

0.1.3

  • Made sure tree shaking is working
  • Removed DevTools from the code, but it still works if you have browser extension

0.1.2

  • Fixed duplicating vendor bundle code
  • Reduced overall bundle size by disabling devtool in production

0.1.1

  • Fixed running it on Windows machines

0.1.0

  • Updated webpack to a stable version

0.0.3

  • Added pre-push git hook
  • Added preview task

0.0.2

  • Added Redux Dev Tools.
  • Renamed client to source
  • Made sure logger and DevTools are loaded only in development

0.0.1

Initial release

About


Languages

Language:JavaScript 86.0%Language:CSS 13.8%Language:HTML 0.2%