
📅 2025-12-16
➡️ Supabase 타입 생성과 Next.js 번들 최적화에 대해 새롭게 알게 된 것 또는 헷갈리는 부분 정리
🔗 Generating TypeScript Types | Supabase Docs
설치
npm i -D supabase
npx supabase login
npx supabase init
타입 생성 스크립트 설정
package.json"gen:types": "supabase gen types typescript --project-id iliskgpwcsahcqctogsn --schema public > database.types.ts"npm run gen:types → 실행 시 database.types.ts 파일이 자동 생성됨Database 타입을 Supabase Client에 주입하여 완전한 타입 안정성 확보브라우저 클라이언트
import { createBrowserClient } from "@supabase/ssr";
import { Database } from "../../database.types";
export function createClient() {
return createBrowserClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!
);
}
const browserClient = createClient();
export default browserClient;
서버 클라이언트
import { createServerClient } from "@supabase/ssr";
import { cookies } from "next/headers";
import { Database } from "../../database.types";
export async function createClient() {
const cookieStore = await cookies();
return createServerClient<Database>(
process.env.NEXT_PUBLIC_SUPABASE_URL!,
process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY!,
{
cookies: {
getAll() {
return cookieStore.getAll();
},
setAll(cookiesToSet) {
try {
cookiesToSet.forEach(({ name, value, options }) =>
cookieStore.set(name, value, options)
);
} catch {
// The `setAll` method was called from a Server Component.
// This can be ignored if you have middleware refreshing
// user sessions.
}
},
},
}
);
}
설치
yarn add -D @next/bundle-analyzer
설정
next.config.tsimport type { NextConfig } from "next";
import bundleAnalyzer from "@next/bundle-analyzer";
const withBundleAnalyzer = bundleAnalyzer({
enabled: process.env.ANALYZE === "true",
});
const nextConfig: NextConfig = {
images: {
remotePatterns: [
{
protocol: "https",
hostname: "picsum.photos",
},
],
},
};
export default withBundleAnalyzer(nextConfig);빌드 실행
ANALYZE=true yarn build
→ 빌드 후 번들 시각화 페이지 자동 오픈

활용 포인트
dynamic import (지연 로딩)
import dynamic from "next/dynamic";
const HeavyChart = dynamic(
() => import("@/components/HeavyChart"),
{ ssr: false } // 서버 사이드 렌더링시 절대 참여하지 않도록 해주는 옵션
);
모듈 단위 동적 import
const { getBooks } = await import("./server-action");