0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

create reat app 環境構築メモ

Last updated at Posted at 2019-07-19

前の記事で書いたようにReduxはちょっとめんどうです。
業務ではRedux使っているものの、プライベートではReactのみでサイト作ろうと思います。

簡単でした。
Reactのひな形を簡単に作れるcreate-react-appを利用します。

導入

create-react-appコマンドをインストール、アプリ作成

npm install -g create-react-app
create-react-app hello-world

サーバーを開始する

作ったアプリのディレクトリ(今回はhello-world)に行き以下のコマンドを実行
サーバーが起動し、http://localhost:3000 などのURLでアプリを見ることができます。

npm start

eslint設定

eslintとprettierのモジュールをインストール


yarn add -D eslint prettier eslint-plugin-prettier eslint-config-prettier
yarn add -D eslint-plugin-react eslint-config-react-app eslint-plugin-import eslint-plugin-flowtype eslint-plugin-jsx-a11y
yarn add -D eslint-plugin-standard eslint-config-standard eslint-plugin-node eslint-plugin-promise

eslint設定ファイル追加

cat<<EOF > .eslintrc.json
{
  "extends": [
    "standard",
    "plugin:prettier/recommended"
  ],
  "plugins": [
    "react",
    "prettier"
  ],
  "parser": "babel-eslint",
  "parserOptions": {},
  "env": {
    "browser": true,
    "es6": true
  },
  "globals": {
    "it": false
  },
  "rules": {
    "prettier/prettier": "error",
    "react/jsx-uses-react": 1,
    "react/jsx-uses-vars": 1,
    "no-console": "warn",
    // warning  Definition for rule 'jsx-a11y/href-no-hash' was not found に対応
    "jsx-a11y/href-no-hash": "off",
    "jsx-a11y/anchor-is-valid": "off"
  }
}
EOF



cat<<EOF > .eslintignore
node_modules
**/*.min.js
src/registerServiceWorker.js
EOF

cat<<EOF > .prettierrc
{
  "singleQuote": false,
  "trailingComma": "es5",
  "semi": false
}
EOF

参考

Intellijの設定

lint設定.png
プログラム: eslint のPATH (プロジェクトのディレクトリ/node_modules/.bin/eslint )
引数: --fix $FileDir$

拡張オプション
Auto-save edited files to trigger the watcherのチェックを外します ※付けると、編集するたびにコードフォーマットされてうざいです。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?