28-feature-패키지-번들링-최적화#29
Merged
Hidden character warning
The head ref may contain hidden characters: "28-feature-\ud328\ud0a4\uc9c0-\ubc88\ub4e4\ub9c1-\ucd5c\uc801\ud654"
Merged
Conversation
Closed
6 tasks
- pnpm-lock.yaml에 clsx 및 tailwind-merge 패키지 추가 - react-button의 build:analyze 스크립트에 ANALYZE 환경변수 추가 - vite.config.ts에서 시각화 도구 설정을 환경변수에 따라 조건부로 적용하도록 수정
- pnpm-lock.yaml에 rollup-plugin-visualizer 패키지 추가 - react-button의 package.json에 rollup-plugin-visualizer 의존성 추가
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
배경 (Problem)
원인분석
번들 크기 92.4KB 구성 분석에서 2000 줄이 넘는 tailwind-merge 가 전체 크기의 89% 차지
주요 변경사항
번들 크기 최적화 코드라인 : 2015→ 총 147 lines (-93%), unpacked 92.4kb → 13.5kb(-85%)
clsx,tailwind-merge를 peer dependencies로 이동왜 external 처리가 필요한가?
peerDependencies로만 지정하면 패키지 설치 시 소비자가 해당 모듈을 설치해야 한다는 사실만 보장합니다.
하지만, 빌드 단계에서 별도로 external로 지정하지 않으면 번들러는 여전히 해당 모듈을 라이브러리 번들 안에 포함시켜 버릴 수 있습니다.
이를 방치하면 다음 문제가 발생합니다:
우리 라이브러리가 특정 버전의 clsx를 내장하고 있으면, 사용자 프로젝트가 다른 버전 clsx를 쓰고 있을 때 React Tree 안에서 서로 다른 clsx 인스턴스가 존재하게 되고 함수 레벨 유틸이라도 유지보수성 문제를 일으킬 수 있습니다. external로 처리하면 항상 사용자 프로젝트에서 설치한 단일 인스턴스만 존재하게 되어 안전합니다. 같은 맥락으로 clsx나 tailwind-merge도 프로젝트마다 다른 버전이 충돌할 수 있습니다.
rollup-plugin-visualizer를 통한 번들 크기 모니터링analyze.js추가로 번들 크기 추적 가능리스크 & 대응