본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

서버 사이드 렌더링 / SSR

원문 보기 위키 갱신

antd-mobile을 Next.js나 Remix 같은 SSR 환경에서 쓰는 방법을 정리한 가이드예요. SSR 지원은 아직 초기 단계라는 점을 먼저 알아 두세요.

출처: 문서

본문

SSR(서버 사이드 렌더링) 지원은 아직 초기 단계예요. 사용 중에 버그를 발견하면 이슈를 제출해 주세요.

Next.js

Next.js에서 antd-mobile을 사용하려면 추가 설정이 필요해요.

Next.js 12

먼저 next-transpile-modules를 설치해야 해요:

$ npm install --save-dev next-transpile-modules
# or
$ yarn add -D next-transpile-modules
# or
$ pnpm add -D next-transpile-modules
# or
$ bun add -D next-transpile-modules

그다음 next.config.js에서 설정해요:

const withTM = require('next-transpile-modules')([
  'antd-mobile',
]);

module.exports = withTM({
  // other Next.js configuration in your project
});

Next.js 13

Next.js 13은 외부 의존성(node_modules)의 트랜스파일과 번들링을 자동으로 처리할 수 있어요. next-transpile-modules 패키지를 대체하는 기능이에요.

// next.config.js
const nextConfig = {
  transpilePackages: ['antd-mobile'],
};

module.exports = nextConfig;

app 디렉터리에서 antd-mobile을 사용하려면 파일 상단에 'use client' 지시자를 추가해요.

// app/page.jsx
'use client'

import { Button } from 'antd-mobile'

Remix

Remix에서 antd-mobile을 사용하려면 추가 설정이 필요해요.

tsconfig.json의 compilerOptions.paths 필드에 antd-mobile 설정을 추가하고, include 필드에 global.d.ts를 추가해요:

{
  "include": ["remix.env.d.ts", "global.d.ts", "**/*.ts", "**/*.tsx"],
  "compilerOptions": {
    ...
    "paths": {
      "antd-mobile": ["node_modules/antd-mobile/bundle/antd-mobile.es.js"]
    }
  }
}

프로젝트 루트 디렉터리에 global.d.ts 파일을 추가해요.

declare module 'antd-mobile' {
  export * from 'antd-mobile/es';
}

app/root.tsx에서 스타일 파일을 임포트해요:

import styles from "antd-mobile/bundle/style.css";

export function links() {
  return [{ rel: "stylesheet", href: styles }];
}

더 알아보기

기본 설치와 임포트 방법은 빠른 시작 가이드를 참고하세요. 서버 환경에서 스타일 충돌이 생기면 테마 가이드도 함께 보세요.