dusunax / blog

🏗️ 2024 blog building in progress 🏗️
https://blog-dusuna.vercel.app
0 stars 0 forks source link

feat: Next.js와 이미지 최적화_240509 #8

Closed dusunax closed 4 months ago

dusunax commented 5 months ago

Todo


Next.js와 이미지 최적화_240509

이미지 최적화 레퍼런스

1. 👀 next/image 문서 살펴보기

2. 👀 Make Your Image Loading Blurry in Next.js

https://medium.com/@Furki4_4/make-your-image-loading-blurry-in-next-js-0f0e5bf3dc7c

문서에 명시된 대로 동적 이미지에 대한 Image 구성 요소의 BlurDataUrl 속성에 dataURL을 전달해야 합니다. dataURL은 기본적으로 base64 형식으로 흐린 이미지 데이터를 보유하는 문자열입니다.

3. 👀 placeholder 문서

dusunax commented 5 months ago

240509 작업 내용

이미지 타입

PNG 슬라이드에 next/image placeholder blur 적용

https://github.com/dusunax/blog/assets/94776135/deb0e81c-3d55-4350-a8b4-ae5fd5a0423f

PNG 슬라이드 상세 페이지에 blur 적용

https://github.com/dusunax/blog/assets/94776135/f957ebc4-4a98-497a-9e68-e1f09874a573

PNG 리스트만 퍼포먼스 확인

PDF 리스트까지 퍼포먼스 확인 (유의미.. 한가?)

오늘 만난 오류

오류A

문서에 명시된 대로 동적 이미지에 대한 Image 구성 요소의 BlurDataUrl 속성에 dataURL을 전달해야 합니다. dataURL은 기본적으로 base64 형식으로 흐린 이미지 데이터를 보유하는 문자열입니다.

라이브러리 사용: sharp, plaiceholder: commonJS

const nextConfig = withImages({ experimental: { appDir: true, }, images: { formats: ["image/avif", "image/webp"], }, webpack: (config) => { config.resolve.alias.canvas = false; return config; }, });

export default withPlaiceholder(withContentlayer(nextConfig));

### 오류B
- 서버 컴포넌트 async/await 에러 => 타입스크립트 에러입니다.
  ![image](https://github.com/dusunax/blog/assets/94776135/5415ace0-821e-441e-b1e2-0be9edb88ba5)
  - [Next.js 문서](https://nextjs.org/docs/app/building-your-application/data-fetching/fetching-caching-and-revalidating#fetching-data-on-the-server-with-fetch) To use async/await in a Server Component with TypeScript, you'll need to use TypeScript 5.1.3 or higher and @types/react 18.2.8 or higher.
![image](https://github.com/dusunax/blog/assets/94776135/f26630ed-ed05-4b48-8fdd-1947b6509478)
  - 또는 구 버전에서는 아래의 주석으로 에러를 무시헀었습니다 (이전 공식 문서를 참조하는 레퍼런스에서 찾아볼 수 있습니다.) 
  ```tsx
  {/* @ts-expect-error Async Server Component */}
- 버전업을 해도 왠지 타입 오류가 해결되지 않아서 두 번째 방법으로 주석을 추가한 상태입니다.

오류C

dusunax commented 5 months ago

Next Todo