-
Notifications
You must be signed in to change notification settings - Fork 1
[Init] SVGR 설정 #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Init] SVGR 설정 #19
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
svgo 플러그인으로 최적화하는 방식은 처음 알았는데 정말 신기하네요 .. viewBox 옵션까지 꼼꼼하게 챙겨서 추후에 발생할 수 있는 문제를 사전에 처리해준 점도 너무 좋습니다!
또한 공식 문서에서 권장하는 방식으로 타입 지원을 처리한 것도 너무 너무 좋습니다! 문제 없는 거 같아 어푸할게용 수고하셨어요 ~~
(앗차차찿차 충돌해결 꼭 해주세요 !!!)
| <div> | ||
| <h1>Welcome to the Home Page</h1> | ||
| <img src={KERORO} alt="Keroro" /> | ||
| <Heart aria-label= "좋아요" /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aria-label로 접근성 챙긴 것 완전 good
|
꺅 작업하시느라 수고 많으셨습니다 🖤 저도 전에 SVGR 초기 세팅을 맡아본 적이 있는데, SVGO 최적화는 유지하면서
|
| svgr({ | ||
| svgrOptions: { | ||
| plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"], | ||
| svgoConfig: { | ||
| plugins: [ | ||
| { | ||
| name: "preset-default", | ||
| params: { | ||
| overrides: { | ||
| removeViewBox: false, | ||
| } | ||
| } | ||
| } | ||
| ] | ||
| }, | ||
| } | ||
| })], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
?react 쿼리로 SVG 사용 방식을 명확히 나눠둔 점이 좋았습니다
odukong
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SVGR에 필요한 설정들 잘 적용된 것 같습니다!
저도 SVGO로 최적화하면서, 리사이징 이슈 없도록 viewBox 옵션을 적용할 수 있는 점은 몰랐는데 새롭게 배워가요!!! 짱짱 수고하셨어요💞🙌🏻 어푸어푸~~
🚀 빌드 결과❌ 린트 검사 실패 |
|
어라 |
✏️ Summary
close [Init] SVGR 설정 #15
Vite(React + TypeScript)에서 SVG를 React 컴포넌트로 import할 수 있도록 SVGR 설정을 추가했습니다.
SVG 최적화(SVGO)를 적용하되, 아이콘/일러스트가 CSS로 리사이즈될 때 깨질 수 있는 케이스를 방지하기 위해 viewBox는 보존하도록 구성했습니다.
📑 Tasks
1) SVGR 설정 (SVG → React Component 변환)
SVGR은 SVG 파일을 React 컴포넌트로 변환해서 JSX로 렌더링하기 위한 설정입니다.
vite-plugin-svgr설치 (Vite 플러그인)vite.config.ts에svgr()등록?react쿼리로 import된 SVG만 컴포넌트 변환되도록 사용 방식 고정vite-env.d.ts에 타입 reference 추가2) SVGO 설정 (SVG 최적화)
SVG 파일의 불필요한 속성/메타데이터를 정리해서 더 가볍게 만들기 위한 최적화 단계입니다.
@svgr/plugin-svgo설치svgrOptions.plugins에 SVGO 플러그인 추가3) viewBox 보존 처리
viewBox는 SVG 내부 좌표계/뷰포트 범위를 정의하는 값입니다.removeViewBox가 켜져 있을 때 발생하는 문제 !
SVGO의
removeViewBox는 “width/height와 동일한 viewBox를 제거”하는 최적화를 할 수 있는데, viewBox가 없어지면 SVG가 부모 컨테이너에 맞춰 스케일링이 어려워져 아이콘이 컨테이너를 못 채우거나 CSS로 크기를 줄였을 때 클리핑(잘림) 이 발생할 수 있습니다.그래서 이번 PR에서는 최적화는 켜되, viewBox는 유지하도록
preset-default를 사용하면서removeViewBox만 override로 비활성화했습니다 !4) 사용 예시 추가 (동작 확인용 !)
절대경로 예시(케로로 이미지) 옆에
SVGR 아이콘 import예시를 같이 추가했습니다 !!사용 방법 정리
import Icon from "heart.svg?react"👀 To Reviewer
🔔 ETC