Create React app with Vite and other setting === ![](https://i.imgur.com/98iEo02.png) --- ###### tags: `vite`, `eslint`, `prettier` ## Commands for creating React App without template - `npm create vite@latest` and typing `Y` ![](https://i.imgur.com/NUyKXQj.png) - Entering your project name ![](https://i.imgur.com/G9ffwzt.png) - Select a framework ![](https://i.imgur.com/g6mLULT.png) - Select a variant ![](https://i.imgur.com/Qit7QvJ.png) - Done! Then run `npm install` and after installing, run `npm run dev`. ![](https://i.imgur.com/MkByQBg.png) ## Commands for creating React App with template - `npm create vite@latest [project name] -- --template react-ts` ![](https://i.imgur.com/uAm1r66.png) - Done! Then run `npm install` and after installing, run `npm run dev`. ## Eslint setup - npm version 6 - `npm init @eslint/config --config semistandard` - npm version 7+ - `npm init @eslint/config -- --config semistandard` - General use (Will be using this) - `npm init @eslint/config` - How would you like to use ESLint? (**To check syntax, find problems, and enforce code style**) ![](https://i.imgur.com/jKUe59Y.png) - What type of modules does your project use?(**JavaScript modules (import/export)**) ![](https://i.imgur.com/yuqg3e9.png) - Which framework does your project use? (Depends on your project) ![](https://i.imgur.com/MIHB0wP.png) - Does your project use TypeScript? (**Yes**) ![](https://i.imgur.com/n9ecp9I.png) - Where does your code run? (**Browser**) ![](https://i.imgur.com/qE6bEiJ.png) - How would you like to define a style for your project? (**Answer questions about your style**) ![](https://i.imgur.com/pDqKFal.png) - And answer based on ![](https://i.imgur.com/dHVJfZC.png) - Would you like to install them now? (**Yes**) - `npm i -D eslint-plugin react@latest @typescript-eslint/eslint-plugin@latest @typescript-eslint/parser@latest eslint@latest` ![](https://i.imgur.com/p70KaQG.png) - Which pacjage manager do you want to use? (**Depends on you**) ![](https://i.imgur.com/GqT3iub.png) - Install jsx-a11y `npm i eslint-plugin-jsx-a11y --save-dev` - Install react/hooks `npm i eslint-plugin-react-hooks --save-dev` - Install airbnb `npm install eslint-config-airbnb-typescript --save-dev` - Install ESLint TypeScript related dependencies. - `npm i -D @typescript-eslint/parser eslint-import-resolver-typescript` - Create `.eslintrc.json`, and setup config ```json { "extends": [ "eslint:recommended", "plugin:import/errors", "plugin:react/recommended", "plugin:jsx-a11y/recommended", "plugin:react-hooks/recommended", "plugin:@typescript-eslint/recommended", "plugin:@typescript-eslint/recommended-requiring-type-checking", "airbnb", "airbnb-typescript", "prettier" ], "rules": { "react/prop-types": 0, "react/react-in-jsx-scope": 0, "@typescript-eslint/no-empty-function": 0, "@typescript-eslint/no-unused-vars": 1 }, "plugins": ["react", "import", "jsx-a11y", "@typescript-eslint"], "parser": "@typescript-eslint/parser", "parserOptions": { "ecmaVersion": 2022, "sourceType": "module", "project": "./tsconfig.json", "ecmaFeatures": { "jsx": true } }, "env": { "es6": true, "browser": true, "node": true }, "settings": { "react": { "version": "detect" }, "import/parsers": { "@typescript-eslint/parser": [".ts", ".tsx"] }, "import/resolver": { "typescript": { "alwaysTryTypes": true } } } } ``` ## Setup Prettier - `npm install prettier eslint-config-prettier eslint-plugin-prettier --save-dev` - Creat `.prettierrc` and setup config ```jsonld= { "tabWidth": 2, "semi": true, "singleQuote": false, "trailingComma": "all", "printWidth": 80, "useTabs": false, "endOfLine": "auto" } ``` ## Pre-commit Hook Here we are going to use Prettier with a pre-commit tool. This can re-format your files that are marked as “staged” via git add before you commit. - `npx mrm@2 lint-staged` ![](https://i.imgur.com/rs32YE3.png) - `.husky` folder and relevant files would be created automatically. ![](https://i.imgur.com/MZek45g.png) - This command will be added in `package.json` automatically, but need to amend like below to include all the formats. ![](https://i.imgur.com/giBTp57.png) - Test, let's change some files and run `git add` and `git commit -m ""`, you should see something like this. - ![](https://i.imgur.com/4qmQ7OH.png) - You can only push it after checking is all done, if there's an error, you won't be able to push.