React + Redux の開発環境構築

#概要
2017/06/30 時点で、記事最後のバージョンでは整合性が取れってます。
インストールコマンドはバージョン指定しないので、最新バージョンになるため、整合性取れない可能性があります。

本記事は下記環境を目標に作成します。

- React + Redux
- 開発ツール：Visual Studio Code
- UIコンポーネント：Material-UI
- ECMAScript 2015 Support(ES6): Babel
- JavaScriptコンパイル：Babel
- JavaScript Style Check：ESLint
- JavaScript Style Check Rules：Airbnb
- CSS Modules：css-loader
- ビルドツール：webpack
- 開発用サーバー：webpack-dev-server

#開発環境構築手順
**1. npmコマンド：NodeJs**

https://nodejs.org/ja/download/

**2. 開発用IDE：Visual Stuido Code**

https://code.visualstudio.com/download

**3. Create Project**

    mkdir Test
    npm init

**4. React**

    npm install --save react react-dom

**5. React型定義：prop-types**

    npm install --save prop-types

**6. Redux**

    npm install --save redux redux-actions redux-logger redux-promise react-redux
    npm install --save-dev redux-devtools

**7. サーバー通信：Isomorphic-fetch**

    npm install --save isomorphic-fetch

**8. UIコンポーネント：Material-UI**

    npm install --save material-ui react-tap-event-plugin

**9. ビルドツール（依存性自動解決）：webpack**

    npm install --save-dev webpack

**10. テストサーバー：webpack-dev-server**

    npm install --save-dev webpack-dev-server

**11. JavaScriptコンパイラ：Babel**

    npm install --save-dev babel-core babel-loader babel-preset-react babel-preset-env

**12. Loaders**

    npm install --save-dev css-loader style-loader source-map-loader

**13. JS Style Check：ESLint**

    npm install --save-dev eslint eslint-loader babel-eslint

**14. JS Style Check default rules：Airbnb**

    npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react

**15. Babelの設定：.babelrc**

    echo {"presets" : ["es2015", "react"], "plugins": ["transform-object-rest-spread"]} > .babelrc

**16. webpackの設定：webpack.config.js**

```js
var path = require('path');

module.exports = {
  devtool: "source-map",
  context: __dirname + "/src",
  entry: './index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'build')
  },
  devServer: {
    contentBase: 'build',
    port: 3000
  },
  module: {
    loaders: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ["babel-loader"],
      },
      {
        test: /\.js$/,
        exclude: /node_modules/,
        loaders: ["eslint-loader"],
      },
      {
        test: /\.html$/,
        loader: "file?name=[name].[ext]",
      },
      {
        test: /\.css$/,
        loaders: ['style-loader', 'css-loader?modules'],
      }
    ],
  },
}
```

**17. ESLintの設定：.eslintrc.json**

```json
{
    "extends": ["eslint:recommended", "plugin:react/recommended", "airbnb"],
    "plugins": [],
    "parserOptions": {
      "ecmaVersion": 6,
      "sourceType": "module",
      "allowImportExportEverywhere": false,
      "codeFrame": false
    },
    "env": {
      "browser": true,
      "es6": true,
      "node": true
    },
    "globals": {},
    "parser": "babel-eslint",
    "rules": {
      "no-console": 1
    }
}
```

**18. Visual Studio Codeの設定：jsconfig.json**

```json
{
    "compilerOptions": {
        "allowJs": true,
        "allowSyntheticDefaultImports": true
    },
    "exclude": [
        "node_modules"
    ]
}
```

**19. BuildとStartコマンドの追加：package.json**

    Add To Scripts:
        "start": "webpack-dev-server",
        "build": "webpack"

**20. BuildとStartコマンド**

    npm run build
    npm start

**21. 空プロジェクトのフォルダ構成**

    test/
       ├─ build/ ← ビルドファイル
       ├─ node_modules/ ← Packages
       ├─ public/ ← 画像など
       ├─ src/
       │   ├─ actions/ ← Actions
       │   ├─ components/ ← カスタマイズコンポーネント
       │   ├─ constants/ ← 定数
       │   ├─ containers/ ← Container
       │   ├─ middleware/ ← Middleware
       │   ├─ reducers/ ← Store
       │   ├─ utils/ ← Utils
       │   └─ index.js ← Index.js
       ├─ styles/ ← css
       ├─ .babel
       ├─ .eslintrc.json
       ├─ jsconfig.json
       ├─ package.json
       └─ webpack.config.js

**22. 2017/06/03時点で、Install完了後のpackage.json**

```json
{
  "name": "xxx",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "webpack-dev-server -d --progress --colors",
    "build": "webpack"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "isomorphic-fetch": "^2.2.1",
    "material-ui": "^0.18.5",
    "prop-types": "^15.5.10",
    "react": "^15.6.1",
    "react-dom": "^15.6.1",
    "react-redux": "^5.0.5",
    "react-scripts": "^1.0.10",
    "react-tap-event-plugin": "^2.0.1",
    "redux": "^3.7.1",
    "redux-actions": "^2.0.3",
    "redux-logger": "^3.0.6",
    "redux-promise": "^0.5.3"
  },
  "devDependencies": {
    "babel-core": "^6.25.0",
    "babel-eslint": "^7.2.3",
    "babel-loader": "^7.1.1",
    "babel-plugin-transform-es2015-template-literals": "^6.22.0",
    "babel-plugin-transform-object-rest-spread": "^6.23.0",
    "babel-preset-es2015": "^6.24.1",
    "babel-preset-react": "^6.24.1",
    "css-loader": "^0.28.4",
    "eslint": "^3.19.0",
    "eslint-config-airbnb": "^15.0.1",
    "eslint-loader": "^1.8.0",
    "eslint-plugin-import": "^2.2.0",
    "eslint-plugin-jsx-a11y": "^5.0.1",
    "eslint-plugin-react": "^7.1.0",
    "redux-devtools": "^3.4.0",
    "source-map-loader": "^0.2.1",
    "style-loader": "^0.18.2",
    "webpack": "^3.0.0",
    "webpack-dev-server": "^2.5.0"
  }
}
```

**23. Package Installの一括実行**

    npm install --save react react-dom react-scripts
    npm install --save prop-types
    npm install --save redux redux-actions redux-logger redux-promise react-redux
    npm install --save-dev redux-devtools
    npm install --save isomorphic-fetch
    npm install --save material-ui react-tap-event-plugin
    npm install --save-dev webpack
    npm install --save-dev webpack-dev-server
    npm install --save-dev babel-core babel-loader babel-preset-react babel-preset-es2015
    npm install --save-dev babel-plugin-transform-es2015-template-literals
    npm install --save-dev babel-plugin-transform-object-rest-spread
    npm install --save-dev css-loader style-loader source-map-loader
    npm install --save-dev eslint eslint-loader babel-eslint
    npm install --save-dev eslint-config-airbnb eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-react