react 프로젝트에서 import순서 정렬

2023. 9. 8. 23:22·React

https://levelup.gitconnected.com/how-to-sort-imports-in-react-project-550f5ce70cbf'

 

prettier와 eslint 중 하나를 선택해서 설정할 수 있다. 

 

package설치

npm install --save-dev @trivago/prettier-plugin-sort-imports
// or use yarn
yarn add --dev @trivago/prettier-plugin-sort-imports

 

.prettierrc에 설정넣어주기 

importOrder, importOrderSeparation을 넣어주면 되는데 

나는 두가지 값을 넣어도 정렬이 되지 않아서 찾아보니 plugins를 넣어줘야 작동을 했다. 

 

importOrderSeparation은 분류마다 개행처리한다는 것

{
  "semi": false,
  "singleQuote": true,
  "tabWidth": 2,
  "useTabs": false,
  "proseWrap": "always",
  "trailingComma": "none",
  "bracketSpacing": true,
  "printWidth": 200,
  "plugins": ["@trivago/prettier-plugin-sort-imports"],
  "importOrder": ["^react(.*)", "^next(.*)", "<THIRD_PARTY_MODULES>", "@/components(.*)", "@/stores(.*)", "@[./]", "^[./]", "@flatten-corp/"],
  "importOrderSeparation": true
}

 

'React' 카테고리의 다른 글

getInitialProps로 header정보 넘기기  (0) 2023.10.26
React Query Promise.all, useQueries  (0) 2023.09.15
react-hook-form validate with zod  (0) 2023.08.17
리액트 오류: React DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node  (0) 2023.08.05
styles jsx  (0) 2023.07.07
'React' 카테고리의 다른 글
  • getInitialProps로 header정보 넘기기
  • React Query Promise.all, useQueries
  • react-hook-form validate with zod
  • 리액트 오류: React DOMException: Failed to execute 'removeChild' on 'Node': The node to be removed is not a child of this node
ssund
ssund
  • ssund
    ssund의 기술블로그
    ssund
  • 전체
    오늘
    어제
    • TECH (82)
      • Next.js (8)
      • React (25)
      • Vite (1)
      • javascript (17)
      • CSS (6)
      • CS (10)
      • AWS (0)
      • Jest (1)
      • CI|CD (0)
      • 알고리즘 (8)
      • Tools (1)
      • Tips (5)
  • 블로그 메뉴

    • 링크

    • 공지사항

    • 인기 글

    • 태그

      커머스프로젝트
      TypeScript
      서버컴포넌트
      배열요소순서
      global-style
      redux
      React
      Array.sort()
      theme-provider
      styled-components
      타입스크립트
      git배포
      app-router
      JavaScript
      react state management
      함수와 메서드차이
      웹브라우저구성
      reat-head
      call signatures
      nextjs
    • 최근 댓글

    • 최근 글

    • hELLO· Designed By정상우.v4.10.0
    ssund
    react 프로젝트에서 import순서 정렬
    상단으로

    티스토리툴바