Closed dusunax closed 4 months ago
next/image
가 자동으로 이미지 타입을 webp로 바꿉니다)https://github.com/dusunax/blog/assets/94776135/deb0e81c-3d55-4350-a8b4-ae5fd5a0423f
https://github.com/dusunax/blog/assets/94776135/f957ebc4-4a98-497a-9e68-e1f09874a573
placeholder blur를 적용하려면 Base64 이미지 필요
문서에 명시된 대로 동적 이미지에 대한 Image 구성 요소의 BlurDataUrl 속성에 dataURL을 전달해야 합니다. dataURL은 기본적으로 base64 형식으로 흐린 이미지 데이터를 보유하는 문자열입니다.
// next.config.mjs
import withPlaiceholder from "@plaiceholder/next";
import withImages from "next-images";
import { withContentlayer } from "next-contentlayer";
/** @type {import('next').NextConfig} */
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 */}
- 버전업을 해도 왠지 타입 오류가 해결되지 않아서 두 번째 방법으로 주석을 추가한 상태입니다.
node:fs
, node:path
를 사용하려 했을 때 발생
Todo
Next.js와 이미지 최적화_240509
이미지 최적화 레퍼런스
1. 👀 next/image 문서 살펴보기
<Image ... priority />
2. 👀 Make Your Image Loading Blurry in Next.js
문서에 명시된 대로 동적 이미지에 대한 Image 구성 요소의 BlurDataUrl 속성에 dataURL을 전달해야 합니다. dataURL은 기본적으로 base64 형식으로 흐린 이미지 데이터를 보유하는 문자열입니다.
3. 👀 placeholder 문서