|
1 | | -import type { StorybookConfig } from '@storybook/nextjs'; |
| 1 | +import type { StorybookConfig } from '@storybook/nextjs-vite'; |
| 2 | +import { mergeConfig } from 'vite'; |
| 3 | +import stylex from '@stylexjs/unplugin'; |
2 | 4 | import { dirname } from 'path'; |
3 | 5 | import { createRequire } from 'module'; // 1. createRequire 불러오기 |
4 | 6 | import path from 'path'; |
5 | 7 | import { fileURLToPath } from 'node:url'; |
| 8 | + |
6 | 9 | // 2. ESM 환경에서 require 기능을 사용하기 위해 생성 |
7 | | -const require = createRequire(import.meta.url); |
| 10 | +const esmRequire = createRequire(import.meta.url); |
| 11 | + |
| 12 | +const MiniCssExtractPlugin = esmRequire('mini-css-extract-plugin'); |
| 13 | +const stylexPlugin = esmRequire('@stylexjs/unplugin').default; |
8 | 14 |
|
9 | 15 | /** |
10 | 16 | * 이 함수는 패키지 이름을 절대 경로로 변환합니다. |
11 | 17 | * Windows + pnpm 환경 호환을 위해 템플릿 리터럴(`${value}/package.json`)을 사용합니다. |
12 | 18 | */ |
13 | 19 | function getAbsolutePath(value: string): string { |
14 | | - return dirname(require.resolve(`${value}/package.json`)); |
| 20 | + return dirname( |
| 21 | + createRequire(import.meta.url).resolve(`${value}/package.json`) |
| 22 | + ); |
15 | 23 | } |
16 | | -const __dirname = dirname(fileURLToPath(import.meta.url)); |
| 24 | +const currentDir = dirname(fileURLToPath(import.meta.url)); |
| 25 | +const rootDir = path.resolve(currentDir, '../'); |
| 26 | + |
17 | 27 | const config: StorybookConfig = { |
18 | 28 | stories: [ |
19 | | - path.resolve(__dirname, '..', 'components') + '/**/*.mdx', |
20 | | - path.resolve(__dirname, '..', 'components') + |
| 29 | + path.resolve(currentDir, '..', 'components') + '/**/*.mdx', |
| 30 | + path.resolve(currentDir, '..', 'components') + |
21 | 31 | '/**/*.stories.@(js|jsx|mjs|ts|tsx)', |
22 | 32 | // '../components/**/*.stories.@(js|jsx|mjs|ts|tsx)', |
23 | 33 | ], |
24 | 34 | addons: [ |
25 | 35 | // getAbsolutePath('@storybook/addon-essentials'), |
26 | 36 | // getAbsolutePath('@storybook/addon-a11y'), |
27 | | - getAbsolutePath('@storybook/addon-webpack5-compiler-babel'), |
| 37 | + // getAbsolutePath('@storybook/addon-webpack5-compiler-babel'), |
28 | 38 | '@storybook/addon-docs', |
29 | 39 | '@nx/storybook/preset', |
30 | 40 | ], |
31 | | - framework: { |
32 | | - name: getAbsolutePath('@storybook/nextjs'), |
33 | | - options: {}, |
34 | | - }, |
| 41 | + // framework: { |
| 42 | + // name: getAbsolutePath('@storybook/nextjs'), |
| 43 | + // options: {}, |
| 44 | + // }, |
| 45 | + /** framework 를 테스트 */ |
| 46 | + framework: { name: '@storybook/nextjs-vite', options: {} }, |
| 47 | + |
35 | 48 | docs: { |
36 | 49 | defaultName: 'Documentation', |
37 | 50 | }, |
38 | 51 | staticDirs: ['../public'], |
39 | | - webpackFinal: async (config) => { |
40 | | - // ✅ [핵심] Webpack이 모듈을 찾을 때 "프로젝트 루트"도 찾아보게 설정 |
41 | | - if (config.resolve) { |
42 | | - config.resolve.modules = [ |
43 | | - ...(config.resolve.modules || []), |
44 | | - // 현재 파일(.storybook/main.ts) 기준 3칸 위(Root)를 모듈 탐색 경로에 추가 |
45 | | - path.resolve(dirname(fileURLToPath(import.meta.url)), '../../../'), |
46 | | - ]; |
47 | | - } |
48 | 52 |
|
49 | | - // ... 기존 StyleX 관련 설정이 있다면 유지 ... |
| 53 | + // webpackFinal: async (config) => { |
| 54 | + // // ✅ [핵심] Webpack이 모듈을 찾을 때 "프로젝트 루트"도 찾아보게 설정 |
| 55 | + // if (config.resolve) { |
| 56 | + // config.resolve.modules = [ |
| 57 | + // ...(config.resolve.modules || []), |
| 58 | + // // 현재 파일(.storybook/main.ts) 기준 3칸 위(Root)를 모듈 탐색 경로에 추가 |
| 59 | + // path.resolve(dirname(fileURLToPath(import.meta.url)), '../../../'), |
| 60 | + // ]; |
| 61 | + // } |
50 | 62 |
|
51 | | - return config; |
52 | | - }, |
53 | | - babel: async (options: any) => { |
54 | | - return { |
55 | | - ...options, |
56 | | - // Next.js 기본 프리셋 사용 |
57 | | - presets: [['next/babel']], |
| 63 | + // // ... 기존 StyleX 관련 설정이 있다면 유지 ... |
| 64 | + |
| 65 | + // return config; |
| 66 | + // }, |
| 67 | + |
| 68 | + // babel: async (options: any) => { |
| 69 | + // return { |
| 70 | + // ...options, |
| 71 | + // // Next.js 기본 프리셋 사용 |
| 72 | + // presets: [['next/babel']], |
| 73 | + // plugins: [ |
| 74 | + // ...(options.plugins || []), |
| 75 | + // [ |
| 76 | + // '@stylexjs/babel-plugin', |
| 77 | + // { |
| 78 | + // dev: process.env.NODE_ENV === 'development', |
| 79 | + // // 🔥 CLI로 CSS를 뽑고 있으므로 runtimeInjection은 반드시 false여야 합니다. |
| 80 | + // runtimeInjection: false, |
| 81 | + // genConditionalClasses: true, |
| 82 | + // treeshakeCompensation: true, |
| 83 | + // unstable_moduleResolution: { |
| 84 | + // type: 'commonJS', |
| 85 | + // // 모노레포 환경에서 루트 경로를 확실하게 잡기 위해 |
| 86 | + // // 현재 파일(.storybook/main.ts) 위치 기준으로 상위 폴더를 지정합니다. |
| 87 | + // rootDir: path.resolve( |
| 88 | + // dirname(fileURLToPath(import.meta.url)), |
| 89 | + // '../../../' |
| 90 | + // ), |
| 91 | + // }, |
| 92 | + // }, |
| 93 | + // ], |
| 94 | + // ], |
| 95 | + // }; |
| 96 | + // }, |
| 97 | + /** 아래는 테스트 */ |
| 98 | + viteFinal: async (config) => { |
| 99 | + return mergeConfig(config, { |
58 | 100 | plugins: [ |
59 | | - ...(options.plugins || []), |
60 | | - [ |
61 | | - '@stylexjs/babel-plugin', |
62 | | - { |
63 | | - dev: process.env.NODE_ENV === 'development', |
64 | | - // 🔥 CLI로 CSS를 뽑고 있으므로 runtimeInjection은 반드시 false여야 합니다. |
65 | | - runtimeInjection: false, |
66 | | - genConditionalClasses: true, |
67 | | - treeshakeCompensation: true, |
68 | | - unstable_moduleResolution: { |
69 | | - type: 'commonJS', |
70 | | - // 모노레포 환경에서 루트 경로를 확실하게 잡기 위해 |
71 | | - // 현재 파일(.storybook/main.ts) 위치 기준으로 상위 폴더를 지정합니다. |
72 | | - rootDir: path.resolve( |
73 | | - dirname(fileURLToPath(import.meta.url)), |
74 | | - '../../../' |
75 | | - ), |
76 | | - }, |
| 101 | + // StyleX 플러그인 추가 (설정 끝) |
| 102 | + stylex.vite({ |
| 103 | + useCSSLayers: true, |
| 104 | + // ... other StyleX configuration options |
| 105 | + unstable_moduleResolution: { |
| 106 | + type: 'commonJS', |
| 107 | + rootDir: rootDir, |
77 | 108 | }, |
78 | | - ], |
| 109 | + }), |
79 | 110 | ], |
80 | | - }; |
| 111 | + resolve: { |
| 112 | + alias: { |
| 113 | + // Next.js의 @/ 경로를 apps/core 폴더로 연결 |
| 114 | + '@': rootDir, |
| 115 | + }, |
| 116 | + }, |
| 117 | + }); |
81 | 118 | }, |
82 | 119 | }; |
83 | 120 |
|
|
0 commit comments