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 1 year has passed since last update.

NextJsでプロジェクトのセットアップをする

Last updated at Posted at 2022-12-17

NextJsでプロジェクトを作成するにあたって環境構築をしました。
EslintやPretterの設定について、今後も行うと思うので、流れを記録しておきます。

新規作成

$ yarn create next-app --typescript

サーバー起動

$ yarn dev

ESLint

設定を追加

package.json
"scripts": {
  "lint": "next lint"
}

インストールと構成

$ yarn lint
.eslintrc.json
{
  "extends": ["eslint:recommended","next/core-web-vitals"]
}

ESLintでTypeScriptのチェック

$ yarn add --dev @typescript-eslint/parser @typescript-eslint/eslint-plugin
.eslintrc.json
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
      "ecmaVersion": "latest",
      "project": "./tsconfig.json",
      "ecmaFeatures": {
      "jsx": true
    }
  },
  "plugins": ["@typescript-eslint"],
  "extends": ["eslint:recommended","next/core-web-vitals","plugin:@typescript-eslint/recommended"]
}

Prettier

インストール

$ yarn add --dev prettier eslint-config-prettier

ESLint と Prettier を連携させる(競合するルールをオフにする)

.eslintrc.json
{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
      "ecmaVersion": "latest",
      "project": "./tsconfig.json",
      "ecmaFeatures": {
      "jsx": true
    }
  },
  "plugins": ["@typescript-eslint"],
  "extends": ["eslint:recommended","next/core-web-vitals","plugin:@typescript-eslint/recommended","prettier"]
}

フォーマットの設定

.prettierrc
{
  "trailingComma": "es5",
  "tabWidth": 2,
  "semi": true,
  "singleQuote": true,
  "jsxSingleQuote": true,
  "printWidth": 60
}

エディターの設定

.vscode/settings.json
{
  "editor.defaultFormatter": "esbenp.prettier-vscode",
  "editor.formatOnSave": true,
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  }
}
0
0
1

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?