ย
์๋ฌด๋๋ Nextjs, tailwind, shadCN๋ฑ ์ฌ๋ฌ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ํผ์ฌ๋ ์ํฉ์์ ์ฌ์ฉํ๋ ค๋ ์ฌ๋ฌ ์๋ก์ฌํญ๋ค์ด ์์๋ค.
ย
1. install(nextjs)
npx storybook@latest init
nextjs Storybook tailwind ์ค์นํ ๋ ์ถ๊ฐ์ ์ผ๋ก ์ค์นํ๊ธฐ!
npm install -D postcss autofrefixer
/** @type {import('postcss-load-config').Config} */ export const plugins = { tailwindcss: {}, autoprefixer: {}, };
์์กด์ฑ ๋ชฉ๋ก
"devDependencies": { "@chromatic-com/storybook": "^1.3.5", "@storybook/addon-a11y": "^8.0.10", "@storybook/addon-essentials": "^8.0.10", "@storybook/addon-interactions": "^8.0.10", "@storybook/addon-links": "^8.0.10", "@storybook/addon-onboarding": "^8.0.10", "@storybook/addon-styling-webpack": "^1.0.0", "@storybook/blocks": "^8.0.10", "@storybook/nextjs": "^8.0.10", "@storybook/react": "^8.0.10", "@storybook/test": "^8.0.10", "autoprefixer": "^10.4.19", "postcss": "^8.4.38", "prettier-plugin-tailwindcss": "^0.5.14", "sass": "^1.77.1", "storybook": "^8.0.10", "tailwindcss": "^3.4.3", "@svgr/webpack": "^8.1.0", // svg ์ฌ์ฉํ๊ธฐ ์ํ ์์กด์ฑ }
ย
ย
์ดํ preview.ts ์ tailwind๊ฐ ์๋ css ํด๋ import ํด์ฃผ๊ธฐ
ย
์ดํ ๋น๋์ ์คํ ๋ฆฌ ํ์ผ๋ค์ ์ ์ธํด์ผํ๊ธฐ ๋๋ฌธ์
next.config์์ ๋น๋์ ์ ์ธ๋ชฉ๋ก์ ์ถ๊ฐ
ย
ย
// next.config.mjs /** @type {import('next').NextConfig} */ const nextConfig = { // ์คํ ๋ฆฌ๋ถ ํ์ฅ์ ์ ๊ฑฐ webpack: (config, { buildId, dev, isServer, defaultLoaders, webpack }) => { config.module.rules.push({ test: /\.stories\.(ts|js|tsx|jsx)$/, loader: 'ignore-loader' }); // ์คํ ๋ฆฌ๋ถ ๋ฃจํธ๊ฒฝ๋ก์ ๊ฑฐ config.module.rules.push({ test: /\.storybook/, loader: 'ignore-loader' }); return config; }, }; export default nextConfig;
ย
์๋๋ alias์ nextjs ํ๊ฒฝ์์ SVG๋ฅผ ์ ์ฉํ๋ ์นํฉ์ค์
SVG๋ nextConifg์์๋ ์ ์ฉํด์ค์ผํจ ์๋ ์ฐธ๊ณ
Nextjs ์์ SVG ํ์ฉํ๊ธฐ// .storybook/main.js import type { StorybookConfig } from '@storybook/nextjs'; import path from 'path'; const config: StorybookConfig = { stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'], addons: [ '@storybook/addon-onboarding', '@storybook/addon-links', '@storybook/addon-essentials', '@chromatic-com/storybook', // ํฌ๋ก๋งํฑ ๋ฐฐํฌ '@storybook/addon-interactions', // ์ปดํฌ๋ํธ ์ํธ์์ฉ ํ ์คํธ '@storybook/addon-a11y', // ์น ์ ๊ทผ์ฑ ๊ฒ์ฌ. ], framework: { name: '@storybook/nextjs', options: {}, }, docs: { autodocs: 'tag', }, staticDirs: ['..\\public'], webpackFinal: async config => { config.module = config.module || {}; config.module.rules = config.module.rules || []; // This modifies the existing image rule to exclude .svg files // since you want to handle those files with @svgr/webpack // svg ์ธ์ํ๊ธฐ ์ํ ์นํฉ ์ค์ const imageRule = config.module.rules.find(rule => rule?.['test']?.test('.svg')); if (imageRule) { imageRule['exclude'] = /\.svg$/; } // Configure .svg files to be loaded with @svgr/webpack // svg ์ธ์ํ๊ธฐ ์ํ ์นํฉ ์ค์ config.module.rules.push({ test: /\.svg$/, use: ['@svgr/webpack'], }); // @ alias ์ค์ if (config.resolve) { config.resolve.alias = { ...config.resolve.alias, '@': path.resolve(__dirname, '../src'), }; } return config; }, }; export default config;
ย
ย
lint์์๋ ์ปดํ์ผ์ ์ ์ธํ๋๋ก ์ค์ ํ๋ค. tsconfig๋ ์ ์ธํ๋ คํ๋๋ฐ
์ด๋ด๊ฒฝ์ฐ ์คํ ๋ฆฌ๋ถ ํ์ผ์์ ํ์
์๋ฌ๊ฐ ๋ฐ์ํด์ ๋ค๋ฅธ ๋ฐฉ๋ฒ์ ์ฐพ์๋ด์ผํ ๊ฒ ๊ฐ์.
{ "extends": [ "next/core-web-vitals", "prettier", "plugin:storybook/recommended" ], "ignorePatterns": [ "**/*.stories.tsx", "**/*.stories.ts", "**/*.stories.js", "**/*.stories.jsx", ".storybook/**" ] }
ย
ย
2. ์คํ
npm run storybook
ย
ย
ย
ย
ย

