$ cp .vscode/settings.sample.json .vscode/settings.json
$ npm run start
> open http://localhost:3000/
$ npx eslint --init
✔ How would you like to use ESLint? · problems
✔ What type of modules does your project use? · esm
✔ Which framework does your project use? · react
✔ Does your project use TypeScript? · No / Yes
✔ Where does your code run? · browser
✔ What format do you want your config file to be in? · JavaScript
✔ Would you like to install them now with npm? · No / Yes
package.json
{
- "eslintConfig": {
- "extends": "react-app",
- "react-app/jest",
- },
}
.eslintrc.js
module.export = {
"extends": [
+ "extends": "react-app",
+ "react-app/jest",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended"
]
$ npm i -D --save-exact prettier
$ touch .prettierrc.json
If you use ESLint, install eslint-config-prettier to make ESLint and Prettier play nice with each other. It turns off all ESLint rules that are unnecessary or might conflict with Prettier. There’s a similar config for Stylelint: stylelint-config-prettier
cf. https://prettier.io/docs/en/install.html#eslint-and-other-linters
$ npm i -D eslint-config-prettier
.eslintrc.js
{
"extends": [
"react-app",
"react-app/jest",
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
+ "prettier"
],
# ESLint
$ npm run lint
# ESLInt --fix
$ npm run lint:fix
# ESLint --fix with Prettier format
$ npm run format
Auto format with file save!
.vscode/setting.json
{
"files.exclude": {
"**/node_modules": true
},
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"[markdown]": {
"files.trimTrailingWhitespace": false
}
}
@/*
->./src/*
~/*
->./public/*
$ touch tsconfig.paths.json
tsconfig.paths.json
{
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["src/*"],
"~/*": ["public/*"]
}
}
}
tsconfig.json
{
+ "extends": "./tsconfig.paths.json",
"compilerOptions": {
$ npm i -D react-app-rewired
$ touch config-overrides.js
config-overrides.js
const path = require('path');
module.exports = (config) => {
config.resolve = {
...config.resolve,
alias: {
...config.alias,
'@': path.resolve(__dirname, './src'),
'~': path.resolve(__dirname, './public'),
},
};
return config;
};
.eslintignore
/config-overrides.js
package.json
{
"scripts": {
- "start": "react-scripts start",
- "build": "react-scripts build",
- "test": "react-scripts test",
- "eject": "react-scripts eject",
+ "start": "react-app-rewired start",
+ "build": "react-app-rewired build",
+ "test": "react-app-rewired test",
+ "eject": "react-app-rewired eject",
}
.vscode/settings.json
{
+ "path-autocomplete.pathMappings": {
+ "@": "${folder}/src",
+ "~": "${folder}/public"
+ }
}
eslint-import-resolver-typescript
$ npm i -D eslint-import-resolver-typescript
.eslintrc.js
{
"settings": {
"react": {
"version": "detect"
},
+ "import/resolver": {
+ "typescript": {
+ "project": "./tsconfig.json"
+ }
+ }
},
"extends": [
$ npm i -D eslint-plugin-unused-imports
.eslintrc.json
{
"plugins": [
"react",
"@typescript-eslint",
+ "unused-imports"
],
"rules": {
+ "@typescript-eslint/no-unused-vars": "off", // or "no-unused-vars": "off",
+ "unused-imports/no-unused-imports": "error",
+ "unused-imports/no-unused-vars": [
+ "warn",
+ { "vars": "all", "varsIgnorePattern": "^_", "args": "after-used", "argsIgnorePattern": "^_" }
+ ]
}
}
$ npm i -D eslint-plugin-import
.eslintrc.json
{
"plugins": [
"react",
"@typescript-eslint",
"unused-imports",
+ "import"
],
"rules": {
+ "import/order": []
}
}
import/order: Enforce a convention in module import order
e.g.
{
"rules": {
"import/order": [
"error",
{
"groups": [ "builtin", "external","internal", ["parent", "sibling"], "object", "type", "index"
],
// never | always | ignore | always-and-inside-groups
"newlines-between": "never",
// FIXME: ?
// > This defines import types that are not handled by configured pathGroups. This is mostly needed when you want to handle path groups that look like external imports.
"pathGroupsExcludedImportTypes": ["builtin"],
// sort in ascending order & ignore case
"alphabetize": { "order": "asc", "caseInsensitive": true },
// custom group
"pathGroups": [
{
"pattern": "react**",
"group": "external",
"position": "before"
},
{
"pattern": "@reduxjs/**",
"group": "external",
"position": "before"
},
{
"pattern": "{@/libs,@/features,@/app}",
"group": "internal",
"position": "before"
},
{
"pattern": "{@/components,@/pages}",
"group": "internal",
"position": "before"
},
// Import CSS module at last
{
"pattern": "./**.module.css",
"group": "index",
"position": "after"
}
]
}
]
}
}
cf. https://zenn.dev/appare45/articles/7f667031aab94b
- 🙅
npm audit
- 🙆
npm audit --production
This project was bootstrapped with Create React App.
In the project directory, you can run:
Runs the app in the development mode.
Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.
You will also see any lint errors in the console.
Launches the test runner in the interactive watch mode.
See the section about running tests for more information.
Builds the app for production to the build
folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the filenames include the hashes.
Your app is ready to be deployed!
See the section about deployment for more information.
Note: this is a one-way operation. Once you eject
, you can’t go back!
If you aren’t satisfied with the build tool and configuration choices, you can eject
at any time. This command will remove the single build dependency from your project.
Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except eject
will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own.
You don’t have to ever use eject
. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it.
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.