๐ฆ
34์ผ์ฐจ
Part 10. React ๋ก ์ผํ๋ชฐ ๋ง๋ค๊ธฐ (React ๊ธฐ๋ณธ)
Ch 3. Creating React Project
Ch 3. Creating React Project
$ npx create-react-app my-app
// package.json
{
"scripts": {
"start": "react-scripts start", // npm start (๊ฐ๋ฐ์ฉ)
"build": "react-scripts build", // npm run build (ํ๋ก๋์
์ฉ)
"test": "react-scripts test", // npm test (ํ
์คํธ์ฉ)
"eject": "react-scripts eject" // npm run eject (๊บผ๋ => create-react-app ์ฌ์ฉX ์ถ์ฒใดใด)
},
}
$ npm run build
$ npx serve -s build
๐ ESLint (React ๊ธฐ๋ณธ ์ ๊ณต) => The pluggable linting utility for JavaScript and JSX
$ npm i eslint -D
$ npx eslint --init
$ npx eslint index.js // eslint ํ์ธ
$ npx eslint index.js --fix // eslint ํ์ธ => fix
// .eslintrc.js
module.exports = {
...
rules: {
semi: ["error", "always"],
},
};
๐ Prettirer => An opinionated code formatter
$ npm i prettier -D
$ npx prettier index.js // eslint ํ์ธ
$ npx prettier index.js --write // eslint ํ์ธ => fix
// .prettierrc.json
{
"singleQuote": true
}
https://prettier.io/docs/en/options.html
https://github.com/prettier/eslint-config-prettier
// eslint-config-prettier
{
...
"eslintConfig": {
"extends": [
"react-app",
"prettier"
]
}
}
๐ husky => Git hooks made easy
https://github.com/typicode/husky
$ npm i husky -D
$ npx husky install
$ npx husky add .husky/pre-commit "npm test"
$ git add -A
$ git commit -m "husky test"
// package.json
{
"scripts": {
"prepare": "husky install",
...
},
}
๐ lint-staged => Run linters on git staged files
$ npm i husky -D
$ npx husky install
$ npx husky add .husky/pre-commit "npx lint-staged"
$ npx i lint-staged -D
// package.json
{
"scripts": {
"prepare": "husky install",
...
},
"lint-staged": {
"**/*.js": [
"eslint --fix",
"prettier --write",
"git add"
]
},
...
}