Comments (1)
pacakage.json 세팅
npm init -y
eslint 세팅 및 실행
npx eslint --init
eslint **/*.js --fix
npx와 npm의 차이?
- npm : 서버에서 받은 라이브러리를 하드디스크에 저장한다.
- npx : 서버에서 받은 라이브러리를 레지스트리에 올리고 cpu가 바로 사용한다.
Babel 세팅(Babel 7 기준)
-
https://babeljs.io/docs/en/babel-preset-env (babel docs)
-
https://ahnheejong.name/articles/ecmascript-tc39/ (stage 관련 정리)
-
https://browserl.ist/ (env target세팅 기준 호환되는 브라우저 리스트를 볼 수 있다.)
-
react 기준 설치
npm i -D @babel/core @babel/preset-env @babel/perset-react
- Webpack과 같은 모듈 번들러에서 Babel 설정을 읽기 위한 라이브러리
npm i -D babel-loader
- .babelrc
{
"presets" : ["@babel/preset-env", "@babel/preset-react"],
"plugins": [ ... ]
}
Webpack 세팅
- Webpack 설치
npm install -D webpack webpack-cli
- webpack.config.js
module.exports = {
module: {
rules: [
{
test: /\.(js | jsx)$/,
exclude: /node_modules/,
use: {
loader: "babel-loader"
}
},
],
resolve : {
extensions : ['*', '.jsx', '.js']
},
}
}
entry 파일 설정의 default는
src/index.js
output 설정의 default는main/dist.js
entry는 무조건 .js파일을 설정
webpack --mode development
webpack --mode production
development : minify가 적용되지 않은 상태
production : minify가 적용된 상태
React 설치
npm install react react-dom
index.js
수정App.js
작성index.html
작성html-webpack-plugin
과html-loader
설치
npm install -D html-webpack-plugin html-loader
- webpack.config.js 수정
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
module: {
rules: [
... ,
{
test: /\.html$/,
exclude: /node_modules/,
use: {
loader: "html-loader",
options: {minimize: true}
}
}
]
},
plugins : [
new HtmlWebpackPlugin({
template: "./public/index.html",
filename: "./index.html"
})
]
}
webpack-dev-server 설치
npm install --save-dev webpack-dev-server
- webpack-dev-server 관련 설정 : webpack.config.js
module.exports = {
module: {
rules: [ ... ]
},
plugins : [ ... ],
devServer: {
open : true,
port: 3000
}
}
webpack-dev-server
실행
webpack-dev-server
Bonus
- husky 설치 : Git의 hooks를 쓰기 편하게 만들어준다.
- lint-staged 설치
npm install --save-dev husky lint-staged
- package.json
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"npm run lint:fix",
"git add"
]
},
Sample
from dev-tips.
Related Issues (20)
- React.memo를 컴포넌트 리렌더링 최적화
- JSON.stringify circular structure
- JS에서 시간을 측정해보자
- two depth 이상의 빈 JS 객체를 생성해보자
- Trailing Slash('/')
- react-native-image-picker를 사용해 이미지를 업로드 해보자.
- 개발자 도구를 이용해서 성능 측정하기
- React의 state는 왜 불변성을 유지해야할까? 왜 Immutable.js 를 사용할까? HOT 1
- Infinite Scroll에 데이터가 무제한이라면? (feat.DOM Recycling)
- FOUC(Flash of Unstyled Content)
- no-cache vs no-store
- HTTP 쿠키(Cookie)
- Image Sprite 기법의 문제는 뭘까?
- nth-child vs nth-of-type
- React의 useEffect를 mount시점에 태우고 싶지 않다면?
- External Component를 Styeld Components로 감쌌을 때 에러 해결
- message 객체를 json 형태의 메세지 프로퍼티로 변경해보자!(feat.react-intl)
- lodash tree shaking issue
- css in js
- Uncaught ReferenceError: process is not defined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dev-tips.