Skip to content

Commit

Permalink
docs: with-nextjs page translated into Korean (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaic4o authored Nov 17, 2024
1 parent dd7be18 commit fb19087
Showing 1 changed file with 117 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
---
sidebar_position: 10
---
# NextJS์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ

NextJS์—์„œ๋„ FSD(Feature-Sliced Design) ์•„ํ‚คํ…์ฒ˜๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์ง€๋งŒ, ๋‘ ๊ฐ€์ง€ ์ ์—์„œ NextJS์˜ ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ ์š”๊ตฌ์‚ฌํ•ญ๊ณผ FSD ๊ตฌ์กฐ ๊ฐ„์— ์ถฉ๋Œ์ด ๋ฐœ์ƒํ•ฉ๋‹ˆ๋‹ค:

- `pages` ํด๋”์™€์˜ ๋ผ์šฐํŒ… ๋ฐฉ์‹ ์ฐจ์ด
- NextJS์—์„œ `app` ํด๋”์˜ ์ถฉ๋Œ ๋ฌธ์ œ ๋˜๋Š” ๋ถ€์žฌ

## FSD์™€ NextJS์˜ `ํŽ˜์ด์ง€` ๋ ˆ์ด์–ด ๊ฐ„ ์ถฉ๋Œ {#pages-conflict}

NextJS๋Š” ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋ผ์šฐํŠธ๋ฅผ ์ •์˜ํ•˜๊ธฐ ์œ„ํ•ด `pages` ํด๋”๋ฅผ ์‚ฌ์šฉํ•˜๋ฉฐ, `pages` ํด๋” ๋‚ด์˜ ํŒŒ์ผ์ด URL๊ณผ ๋งคํ•‘๋˜๋„๋ก ์„ค์ •ํ•ฉ๋‹ˆ๋‹ค.
ํ•˜์ง€๋งŒ ์ด ๋ฐฉ์‹์€ FSD(Folder Slice Design) `๊ฐœ๋…์— ๋งž์ง€๋Š” ์•Š์Šต๋‹ˆ๋‹ค`. ํŠนํžˆ, NextJS์˜ ๋ผ์šฐํŒ… ๋ฐฉ์‹์œผ๋กœ๋Š” FSD์˜ ์Šฌ๋ผ์ด์Šค ๊ตฌ์กฐ๋ฅผ ํ‰ํ‰ํ•˜๊ฒŒ ์œ ์ง€ํ•˜๊ธฐ ์–ด๋ ค์šด ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

### NextJS์˜ `pages` ํด๋”๋ฅผ ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ํด๋”๋กœ ์ด๋™ํ•˜๊ธฐ (๊ถŒ์žฅ)

ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ์— `pages` ํด๋”๋ฅผ ๋ฐฐ์น˜ํ•˜๊ณ , FSD ๊ตฌ์กฐ์— ๋งž์ถ˜ ํŽ˜์ด์ง€๋“ค์„ NextJS์˜ `pages` ํด๋”๋กœ ์˜ฎ๊น๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด `src` ํด๋” ๋‚ด์—์„œ FSD ๊ตฌ์กฐ๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

```sh
โ”œโ”€โ”€ pages # NextJS ํŽ˜์ด์ง€ ํด๋”
โ”œโ”€โ”€ src
โ”‚ โ”œโ”€โ”€ app
โ”‚ โ”œโ”€โ”€ entities
โ”‚ โ”œโ”€โ”€ features
โ”‚ โ”œโ”€โ”€ pages # FSD ํŽ˜์ด์ง€ ํด๋”
โ”‚ โ”œโ”€โ”€ shared
โ”‚ โ”œโ”€โ”€ widgets
```

### FSD ๊ตฌ์กฐ ๋‚ด `pages` ํด๋” ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๊ธฐ

๋‹ค๋ฅธ ๋ฐฉ๋ฒ•์œผ๋กœ๋Š” FSD ๊ตฌ์กฐ ๋‚ด์—์„œ `pages` ํด๋”์˜ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•˜์—ฌ NextJS์˜ `pages` ํด๋”์™€ ์ถฉ๋Œ์„ ํ”ผํ•  ์ˆ˜๋„ ์žˆ์Šต๋‹ˆ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, `pages` ํด๋”๋ฅผ `views`๋กœ ์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•˜๋ฉด `src` ํด๋” ๋‚ด์˜ FSD ๊ตฌ์กฐ๋ฅผ ์œ ์ง€ํ•˜๋ฉด์„œ๋„ NextJS์˜ ์š”๊ตฌ ์‚ฌํ•ญ๊ณผ ์ถฉ๋Œํ•˜์ง€ ์•Š๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

```sh
โ”œโ”€โ”€ app
โ”œโ”€โ”€ entities
โ”œโ”€โ”€ features
โ”œโ”€โ”€ pages # NextJS ํŽ˜์ด์ง€ ํด๋”
โ”œโ”€โ”€ views # ์ด๋ฆ„์ด ๋ณ€๊ฒฝ๋œ FSD ํŽ˜์ด์ง€ ํด๋”
โ”œโ”€โ”€ shared
โ”œโ”€โ”€ widgets
```

์ด๋ฆ„์„ ๋ณ€๊ฒฝํ•˜๋Š” ๊ฒฝ์šฐ, ์ด๋ฅผ ํ”„๋กœ์ ํŠธ์˜ README๋‚˜ ๋‚ด๋ถ€ ๋ฌธ์„œ์— ๋ช…ํ™•ํžˆ ๊ธฐ๋กํ•˜์—ฌ ๋ณ€๊ฒฝ ์‚ฌํ•ญ์ด ์ž˜ ์ „๋‹ฌ๋˜๋„๋ก ํ•˜๋Š” ๊ฒƒ์ด ์ข‹์Šต๋‹ˆ๋‹ค. ์ด๋Ÿฌํ•œ ๋ณ€๊ฒฝ์€ ["ํ”„๋กœ์ ํŠธ ์ง€์‹"][project-knowledge]์˜ ์ผ๋ถ€๋กœ ๋ฌธ์„œํ™”ํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•ฉ๋‹ˆ๋‹ค.

## NextJS์—์„œ `app` ํด๋” ๋ถ€์žฌ ๋ฌธ์ œ {#app-absence}

NextJS 13๋ฒ„์ „ ์ดํ•˜์—์„œ๋Š” ๋ช…์‹œ์ ์ธ `app` ํด๋”๊ฐ€ ์—†์œผ๋ฉฐ,
๋Œ€์‹  `_app.tsx` ํŒŒ์ผ์ด ๋ชจ๋“  ํŽ˜์ด์ง€๋ฅผ ๊ฐ์‹ธ๋Š” ์ปดํฌ๋„ŒํŠธ ์—ญํ• ์„ ํ•ฉ๋‹ˆ๋‹ค.

### `pages/_app.tsx` ํŒŒ์ผ์— app ๊ธฐ๋Šฅ ๊ฐ€์ ธ์˜ค๊ธฐ

NextJS ๊ตฌ์กฐ์—์„œ `app` ํด๋”๊ฐ€ ์—†๋Š” ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด, `app` ํด๋” ๋‚ด์— `App` ์ปดํฌ๋„ŒํŠธ๋ฅผ ์ƒ์„ฑํ•˜๊ณ , ์ด๋ฅผ `pages/_app.tsx`์— ๊ฐ€์ ธ์™€ NextJS๊ฐ€ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋„๋ก ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด:

```tsx
// app/providers/index.tsx

const App = ({ Component, pageProps }: AppProps) => {
return (
<Provider1>
<Provider2>
<BaseLayout>
<Component {...pageProps} />
</BaseLayout>
</Provider2>
</Provider1>
);
};

export default App;
```

๊ทธ ๋‹ค์Œ `pages/_app.tsx` ํŒŒ์ผ์—์„œ `App` ์ปดํฌ๋„ŒํŠธ์™€ ํ”„๋กœ์ ํŠธ ์ „์—ญ ์Šคํƒ€์ผ์„ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๊ฐ€์ ธ์˜ฌ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค:

```tsx
// pages/_app.tsx

import 'app/styles/index.scss'

export { default } from 'app/providers';
```

## App Router ์‚ฌ์šฉํ•˜๊ธฐ {#app-router}

NextJS 13.4 ๋ฒ„์ „์—์„œ๋Š” App Router๊ฐ€ ์•ˆ์ •ํ™”๋˜์—ˆ์Šต๋‹ˆ๋‹ค. App Router๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด `pages` ํด๋” ๋Œ€์‹  `app` ํด๋”๋ฅผ ํ†ตํ•ด ๋ผ์šฐํŒ…์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
FSD ์›์น™์„ ์ค€์ˆ˜ํ•˜๊ธฐ ์œ„ํ•ด, NextJS์˜ `app` ํด๋”๋„ `pages` ํด๋”์™€์˜ ์ถฉ๋Œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•œ ๊ฒƒ๊ณผ ๋™์ผํ•œ ๋ฐฉ์‹์œผ๋กœ ๋‹ค๋ฃจ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

์ด๋ฅผ ์œ„ํ•ด NextJS์˜ `app` ํด๋”๋ฅผ ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ๋กœ ์ด๋™ํ•˜๊ณ , FSD ํŽ˜์ด์ง€๋“ค์„ `app` ํด๋”๋กœ ์˜ฎ๊ธฐ๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค.
์ด๋ ‡๊ฒŒ ํ•˜๋ฉด `src` ํด๋” ๋‚ด์—์„œ FSD ํ”„๋กœ์ ํŠธ ๊ตฌ์กฐ๋ฅผ ์œ ์ง€ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
๋˜ํ•œ, App Router์™€ Pages Router๊ฐ€ ํ˜ธํ™˜๋˜๋ฏ€๋กœ `pages` ํด๋”๋ฅผ ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ์— ์ถ”๊ฐ€ํ•˜๋Š” ๊ฒƒ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

```
โ”œโ”€โ”€ app # NextJS app ํด๋”
โ”œโ”€โ”€ pages # NextJS pages ํด๋”
โ”‚ โ”œโ”€โ”€ README.md # ํ•ด๋‹น ํด๋”์˜ ๋ชฉ์ ๊ณผ ์—ญํ• ์— ๋Œ€ํ•œ ์„ค๋ช…
โ”œโ”€โ”€ src
โ”‚ โ”œโ”€โ”€ app # FSD app ํด๋”
โ”‚ โ”œโ”€โ”€ entities
โ”‚ โ”œโ”€โ”€ features
โ”‚ โ”œโ”€โ”€ pages # FSD pages ํด๋”
โ”‚ โ”œโ”€โ”€ shared
โ”‚ โ”œโ”€โ”€ widgets
```

[![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)][ext-app-router-stackblitz]

## ๊ด€๋ จ ํ•ญ๋ชฉ {#see-also}

- [(์Šค๋ ˆ๋“œ) NextJS์˜ pages ๋””๋ ‰ํ† ๋ฆฌ์— ๋Œ€ํ•œ ํ† ๋ก ](https://t.me/feature_sliced/3623)

[project-knowledge]: /docs/about/understanding/knowledge-types
[ext-app-router-stackblitz]: https://stackblitz.com/edit/stackblitz-starters-aiez55?file=README.md


0 comments on commit fb19087

Please sign in to comment.