이 영역을 누르면 첫 페이지로 이동
Nuhends 의 Tech Life 블로그의 첫 페이지로 이동

Nuhends 의 Tech Life

페이지 맨 위로 올라가기

Nuhends 의 Tech Life

IT / Tech / 재테크 관련 뉴스를 최대한 알기 쉽게 전달하는 Tech 블로그 입니다.

[Emotion] emotion(with next v12) 세팅 방법

  • 2022.09.07 19:41
  • 프로그래밍/NextJS
반응형

[Emotion] emotion(with next v12) 세팅 방법

styled components emotion

 

emotion 설치

yarn add @emotion/react @emotion/styled

참고: Emotion 공식 Doc

 

 

SWC 컴파일러 설정

Next 12버전 부터는 Rust 컴파일러 기반의 웹 전용 오픈형 플랫폼 SWC를 사용하게 되면서, 기존 Next(v12 이전)Emotion을 사용하기 위해 필요하던 @emotion/babel-plugin 바벨 플러그인을 대신하여 SWC 컴파일러를 사용할 수 있다. (관련 Next Doc)

// 기존 바벨 사용시 .babelrc 
{
  "presets": ["next/babel", "@emotion/babel-preset-css-prop"],
  "plugins": []
}


이를 위해 next.config.js 에 다음 설정을 추가하자

// next.config.js

module.exports = {
  compiler: {
    emotion: boolean | {
      // default is true. It will be disabled when build type is production.
      sourceMap?: boolean,
      // default is 'dev-only'.
      autoLabel?: 'never' | 'dev-only' | 'always',
      // default is '[local]'.
      // Allowed values: `[local]` `[filename]` and `[dirname]`
      // This option only works when autoLabel is set to 'dev-only' or 'always'.
      // It allows you to define the format of the resulting label.
      // The format is defined via string where variable parts are enclosed in square brackets [].
      // For example labelFormat: "my-classname--[local]", where [local] will be replaced with the name of the variable the result is assigned to.
      labelFormat?: string,
    },
  },
}

// emotion 관련 옵션들을 기본값으로 설정하고 싶다면 
module.exports = {
  compiler: {
    emotion: true,
  },
}

 

 

사용 예제

const Home: NextPage = () => {
  return (
    <StyledWrap>
      <h2>블로그 Home</h2>
      <div>
        Blog
      </div>
    </StyledWrap>
  );
};

export default Home;

const StyledWrap = styled.div`
  background-color: hotpink;
  div {
    font-size: 24px;
  }
`;

 

반응형

 

반응형
저작자표시 비영리 변경금지 (새창열림)

'프로그래밍 > NextJS' 카테고리의 다른 글

[Next.js] 번역-Rendering Fundamentals  (0) 2023.04.09
[Next.js] 딥링크, Next/Link에서 이슈  (0) 2022.10.31
[Next.js] jest로 unit Test 하기  (0) 2022.10.31
[Emotion] CSS 속성 사용시 타입 에러 해결 방법(with Next.js)  (0) 2022.09.07

댓글

이 글 공유하기

  • 구독하기

    구독하기

  • 카카오톡

    카카오톡

  • 라인

    라인

  • 트위터

    트위터

  • Facebook

    Facebook

  • 카카오스토리

    카카오스토리

  • 밴드

    밴드

  • 네이버 블로그

    네이버 블로그

  • Pocket

    Pocket

  • Evernote

    Evernote

다른 글

  • [Next.js] 번역-Rendering Fundamentals

    [Next.js] 번역-Rendering Fundamentals

    2023.04.09
  • [Next.js] 딥링크, Next/Link에서 이슈

    [Next.js] 딥링크, Next/Link에서 이슈

    2022.10.31
  • [Next.js] jest로 unit Test 하기

    [Next.js] jest로 unit Test 하기

    2022.10.31
  • [Emotion] CSS 속성 사용시 타입 에러 해결 방법(with Next.js)

    [Emotion] CSS 속성 사용시 타입 에러 해결 방법(with Next.js)

    2022.09.07
다른 글 더 둘러보기

정보

Nuhends 의 Tech Life 블로그의 첫 페이지로 이동

Nuhends 의 Tech Life

  • Nuhends 의 Tech Life의 첫 페이지로 이동
반응형

검색

메뉴

  • 홈
  • 웹 개발
  • 경제 데이터
  • 경제 공부
  • 방명록

카테고리

  • 분류 전체보기 (127)
    • 프로그래밍 (69)
      • React (3)
      • HTML&CSS 사전 (13)
      • JAVASCRIPT 사전 (11)
      • Algorithm (23)
      • 이슈 정리 (2)
      • 개발 환경 (4)
      • NodeJS (1)
      • Typescript (4)
      • NextJS (5)
      • React-Query (2)
      • ai (1)
    • 경제 데이터 (22)
      • 주식 순위 (20)
      • 경제지표 (2)
    • 경제 공부 (25)
      • 경제 신문 읽기 (3)
      • 세금 재테크 (7)
      • 인사이트 (4)
      • 경제용어정리 (9)
      • 정부 지원 제도 관련 (2)
    • 팁 모음 (11)
      • 인터넷 (5)
      • 생활 (3)
      • SNS 맛집 (3)

최근 글

인기 글

댓글

공지사항

아카이브

태그

  • 프로그래머스
  • 코테
  • softeer
  • 자바스크립트
  • 코테 풀이
  • 코딩테스트
  • 알고리즘
  • javascript

나의 외부 링크

정보

nuhends의 Nuhends 의 Tech Life

Nuhends 의 Tech Life

nuhends

블로그 구독하기

  • 구독하기
  • RSS 피드

방문자

  • 전체 방문자
  • 오늘
  • 어제

티스토리

  • 티스토리 홈
  • 이 블로그 관리하기
  • 글쓰기
Powered by Tistory / Kakao. © nuhends. Designed by Fraccino.

티스토리툴바