Setup a Next.JS project for production-ready

Setup a Next.JS project for production-ready


  1. Create a Next.JS project for this tutorial I’m using bun but you
    can npm or yarn.

bunx create-next-app@latest app-name

Wait till the Dependency installation finishes and navigate to the
project directory

  1. ESLint/Prettier setup overview

Add Packages:
bun add --dev eslint-plugin-prettier eslint-config-prettier
prettier

Modify .eslintrc.json file as below you can change rules as you
like

Image description

Create prettier configs files .prettierrc and .prettierignore

Image description

Image description

  1. Add lint/format scripts to the package.json file
    "lint": "eslint --ext .ts,.tsx ./src",
    "prettier": "prettier {src,__{tests,mocks}__}/**/*.{ts,tsx}",
    "format:check": "bun run prettier --check",
    "format:fix": "bun run prettier  --write",

Enter fullscreen mode

Exit fullscreen mode

  1. Add Pre-commit Hook.
    You can use Prettier with a pre-commit tool. This can re-format
    your files that are marked as “staged” via git add before you
    commit.

    bunx mrm@2 lint-staged

This will install husky and lint-staged, then add a configuration to the project’s package.json that will automatically format supported files in a pre-commit hook.



Source link
lol

By stp2y

Leave a Reply

Your email address will not be published. Required fields are marked *

No widgets found. Go to Widget page and add the widget in Offcanvas Sidebar Widget Area.