[성능 최적화] console.log 제거

Hyuk·2023년 3월 27일
0

최적화

목록 보기
5/8

📝 production에서 console.log 제거

babel을 이용한 라이브러리로 제거(npm)

.babelrc 파일 생성

.babelrc 파일 생성(폴더구조)

  my-app
  ├── node_modules
+ ├── .babelrc
+ ├── src
  └── package.json

입력

{
  "plugins": [["transform-remove-console", {"exclude": ["error", "warn"]}]]
}

🚫 안된다면?

App.tsx에 추가

if (process.env.NODE_ENV === 'production') {
console.log = () => {}		// log 제거
console.error = () => {}		// error 제거
console.debug = () => {}		// debug 제거
}

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement)

🤓 느낀점

간단하지만 실용적인 최적화인것 같다. nextJS는 자동으로 해주는걸로아는데
cra로 만든 프로젝트는 안해주기때문에 console.log를 한번에 지워주는 것이 
바람직한것 같다.
profile
frontEnd Developer

0개의 댓글