Storybook path alias 설정

2023. 9. 9. 18:17·Frontend/Article
728x90

 

tsconfig의 path에 아래 별칭을 이용하여 사용중이었는데

"@": ["./packages/my-app"],
"@/*": ["./packages/my-app/src/*"],

 

storybook내부에서 아래 별칭을 사용하려면 main.ts에 alias설정을 해줘야 한다. 

https://storybook.js.org/docs/react/builders/webpack#troubleshooting

 

Webpack

Storybook is a frontend workshop for building UI components and pages in isolation. Thousands of teams use it for UI development, testing, and documentation. It’s open source and free.

storybook.js.org

(storybook은 webpack으로 빌드하도록 해놓았다 vite x)

/** @type { import('@storybook/react-webpack5').StorybookConfig } */
import path from 'path';

const config = {
  ...(생략)
  webpackFinal: async (config) => {
    config.resolve.alias = {
      ...config.resolve?.alias,
      '@': path.resolve(__dirname, '../src'),
    };
    return config;
  },
};
export default config;

위와 같은 형태로 하면 프로젝트 내에서  @/Icon 형태로 썼을 때 제대로 경로를 찾는다.

 

 

(참고용)

 

Resolve | 웹팩

웹팩은 모듈 번들러입니다. 주요 목적은 브라우저에서 사용할 수 있도록 JavaScript 파일을 번들로 묶는 것이지만, 리소스나 애셋을 변환하고 번들링 또는 패키징할 수도 있습니다.

webpack.kr

 

728x90
저작자표시 비영리 (새창열림)

'Frontend > Article' 카테고리의 다른 글

rollup-plugin-postcss의 SASS 파일 내 custom alias 처리 문제  (0) 2023.10.14
Style Dictionary 사용 방법 정리(feat. 피그마 디자인 토큰 가공하기)  (0) 2023.09.23
자바스크립트의 숫자(Number)형 (Feat. 부동 소수점 vs 고정 소수점)  (0) 2023.05.07
VanillaJs로 무한 스크롤 구현하기(feat: Intersection Observer)  (0) 2023.02.12
[Js] 2차원 배열 new Array().fill()로 값 할당할 때 주의할 점  (0) 2022.09.18
'Frontend/Article' 카테고리의 다른 글
  • rollup-plugin-postcss의 SASS 파일 내 custom alias 처리 문제
  • Style Dictionary 사용 방법 정리(feat. 피그마 디자인 토큰 가공하기)
  • 자바스크립트의 숫자(Number)형 (Feat. 부동 소수점 vs 고정 소수점)
  • VanillaJs로 무한 스크롤 구현하기(feat: Intersection Observer)
BeNI
BeNI
코딩하는 블로그
  • BeNI
    코딩못하는컴공
    BeNI
  • 전체
    오늘
    어제
    • Menu (253)
      • My profile (1)
      • 회고 | 후기 (8)
      • Frontend (65)
        • Article (11)
        • Study (35)
        • 프로그래머스 FE 데브코스 (19)
      • Backend (0)
      • Algorithm (58)
        • Solution (46)
        • Study (12)
      • Major (111)
        • C&C++ (23)
        • Java (20)
        • Data Structure (14)
        • Computer Network (12)
        • Database (15)
        • Linux (6)
        • Architecture (3)
        • Lisp (15)
        • OS (1)
        • Security (2)
      • etc (2)
  • 링크

    • 깃허브
    • 방명록
  • 인기 글

  • 최근 댓글

  • 최근 글

  • 태그

    Algorithm
    lisp
    백준
    데브코스
    C++
    리팩토링
    자료구조
    프로그래머스
    react
    파일처리
  • hELLO· Designed By정상우.v4.10.2
BeNI
Storybook path alias 설정
상단으로

티스토리툴바