Skip to content

Commit a87be73

Browse files
authored
Merge pull request #72 from Hys-Lee/ci
feat: 스토리북 nextjs-vite 및 stylex vite기반으로 변경
2 parents 1510083 + ffd561f commit a87be73

File tree

16 files changed

+282
-1214
lines changed

16 files changed

+282
-1214
lines changed

apps/core/.storybook/_template/story.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Meta, StoryObj } from '@storybook/react/dist';
1+
import type { Meta, StoryObj } from '@storybook/nextjs-vite';
22
import {{pascalCase name}} from './{{pascalCase name}}';
33

44
const meta: Meta<typeof {{pascalCase name}}> = {

apps/core/.storybook/main.ts

Lines changed: 85 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,83 +1,120 @@
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';
24
import { dirname } from 'path';
35
import { createRequire } from 'module'; // 1. createRequire 불러오기
46
import path from 'path';
57
import { fileURLToPath } from 'node:url';
8+
69
// 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;
814

915
/**
1016
* 이 함수는 패키지 이름을 절대 경로로 변환합니다.
1117
* Windows + pnpm 환경 호환을 위해 템플릿 리터럴(`${value}/package.json`)을 사용합니다.
1218
*/
1319
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+
);
1523
}
16-
const __dirname = dirname(fileURLToPath(import.meta.url));
24+
const currentDir = dirname(fileURLToPath(import.meta.url));
25+
const rootDir = path.resolve(currentDir, '../');
26+
1727
const config: StorybookConfig = {
1828
stories: [
19-
path.resolve(__dirname, '..', 'components') + '/**/*.mdx',
20-
path.resolve(__dirname, '..', 'components') +
29+
path.resolve(currentDir, '..', 'components') + '/**/*.mdx',
30+
path.resolve(currentDir, '..', 'components') +
2131
'/**/*.stories.@(js|jsx|mjs|ts|tsx)',
2232
// '../components/**/*.stories.@(js|jsx|mjs|ts|tsx)',
2333
],
2434
addons: [
2535
// getAbsolutePath('@storybook/addon-essentials'),
2636
// getAbsolutePath('@storybook/addon-a11y'),
27-
getAbsolutePath('@storybook/addon-webpack5-compiler-babel'),
37+
// getAbsolutePath('@storybook/addon-webpack5-compiler-babel'),
2838
'@storybook/addon-docs',
2939
'@nx/storybook/preset',
3040
],
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+
3548
docs: {
3649
defaultName: 'Documentation',
3750
},
3851
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-
}
4852

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+
// }
5062

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, {
58100
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,
77108
},
78-
],
109+
}),
79110
],
80-
};
111+
resolve: {
112+
alias: {
113+
// Next.js의 @/ 경로를 apps/core 폴더로 연결
114+
'@': rootDir,
115+
},
116+
},
117+
});
81118
},
82119
};
83120

apps/core/.storybook/preview.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import type { Preview } from '@storybook/react';
1+
import type { Preview } from '@storybook/nextjs-vite';
22

3-
import './stylex_bundle.css';
3+
// import './stylex_bundle.css';
4+
import './stylex.css';
45

56
const preview: Preview = {
67
tags: ['autodocs'],

apps/core/.storybook/stylex.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@layer stylex;

apps/core/.storybook/stylex_bundle.css

Lines changed: 0 additions & 3 deletions
This file was deleted.

apps/core/.storybook/template/StoryTemplate.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

apps/core/.storybook/template/StoryTemplate.stories.js

Lines changed: 0 additions & 20 deletions
This file was deleted.

apps/core/.storybook/template/tokens.stylex.js

Lines changed: 0 additions & 13 deletions
This file was deleted.

apps/core/.storybook/tsconfig.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

apps/core/components/template/StoryTemplate.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Meta, StoryObj } from '@storybook/react/dist';
1+
import type { Meta, StoryObj } from '@storybook/nextjs-vite';
22
import StoryTemplate from './StoryTemplate';
33

44
const meta: Meta<typeof StoryTemplate> = {

0 commit comments

Comments
 (0)