๐Ÿค ์€์ง€log ๐Ÿค

[NextJS] NextJS์—์„œ Styled-components ์‚ฌ์šฉํ•˜๊ธฐ ๋ณธ๋ฌธ

๐ŸŒท Next JS

[NextJS] NextJS์—์„œ Styled-components ์‚ฌ์šฉํ•˜๊ธฐ

Eun_zii 2022. 12. 5. 13:38

 

 

npm i styled-components
npm i @types/styled-components

 

styled-components ๋ฅผ ์„ค์น˜ํ•ฉ๋‹ˆ๋‹ค.

 

npm install babel-plugin-styled-components
npm i babe-preset-next

 

babel plugin ์„ ์„ค์น˜ํ•˜๊ณ  .babelrc ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

 

Next.js๋Š” ํŽ˜์ด์ง€ ์ ‘์† ์‹œ SSR๋ฅผ ์ด์šฉํ•˜๊ณ  ์ดํ›„ ํŽ˜์ด์ง€ ์ด๋™ ์‹œ CSR๋ฅผ ์ด์šฉํ•˜์—ฌ ํŽ˜์ด์ง€๋ฅผ ๋ Œ๋”๋งํ•ฉ๋‹ˆ๋‹ค.

์ด๋•Œ server์™€ client์—์„œ ์ƒ์„ฑํ•˜๋Š” class ํ•ด์‹œ๊ฐ’์ด ๋‹ฌ๋ผ ์ถฉ๋Œ๋กœ ์ธํ•ด ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

babel ์„ค์ •์œผ๋กœ ์ถฉ๋Œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ• ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

ํ”„๋กœ์ ํŠธ ๋ฃจํŠธ ํด๋”์— .babelrc ํŒŒ์ผ ์ƒ์„ฑ

 

{
  "presets": ["next/babel"],
  "plugins": [
    [
      "babel-plugin-styled-components",
      { "fileName": true, "displayName": true, "pure": true, "ssr": true }
    ]
  ]
}

 

.eslintrc.json ์„ค์ •

 

{
  "extends": ["next/babel", "next/core-web-vitals"]
}
728x90