Skip to content

Commit 300a4af

Browse files
committed
feat: add storybook for web (#32)
running npm run storybok:web will launch storybook in the browser.
1 parent cfeb792 commit 300a4af

File tree

5 files changed

+4120
-1277
lines changed

5 files changed

+4120
-1277
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,6 @@ expo-env.d.ts
2828
/.idea
2929
# Tamagui UI generates a lot of cache files
3030
.tamagui
31+
32+
*storybook.log
33+
/storybook-static

.storybook/main.ts

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,53 @@
1-
import { StorybookConfig } from '@storybook/react-native'
1+
import type { StorybookConfig as WebStorybookConfig } from '@storybook/react-webpack5'
2+
import type { StorybookConfig as RNStorybookConfig } from '@storybook/react-native'
23

3-
const main: StorybookConfig = {
4-
stories: ['../src/components/**/*.stories.?(ts|tsx|js|jsx)'],
5-
addons: ['@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-actions'],
6-
}
4+
const isWeb = process.env.STORYBOOK_WEB
5+
import path from 'path'
6+
import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
7+
8+
let config: WebStorybookConfig | RNStorybookConfig
79

8-
export default main
10+
if (isWeb) {
11+
config = {
12+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
13+
addons: [
14+
'@storybook/addon-essentials',
15+
'@chromatic-com/storybook',
16+
'@storybook/addon-interactions',
17+
{
18+
name: '@storybook/addon-react-native-web',
19+
options: {
20+
projectRoot: '../',
21+
modulesToTranspile: [],
22+
},
23+
},
24+
'@storybook/addon-webpack5-compiler-babel',
25+
],
26+
framework: {
27+
name: '@storybook/react-webpack5',
28+
options: {},
29+
},
30+
webpackFinal: async (config) => {
31+
if (config.resolve) {
32+
config.resolve.plugins = [
33+
...(config.resolve.plugins || []),
34+
new TsconfigPathsPlugin({
35+
extensions: config.resolve.extensions,
36+
}),
37+
]
38+
39+
config.resolve.alias = {
40+
...config.resolve.alias,
41+
'@': path.resolve(__dirname, '../'),
42+
}
43+
}
44+
return config
45+
},
46+
} as WebStorybookConfig
47+
} else {
48+
config = {
49+
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
50+
addons: ['@storybook/addon-ondevice-controls', '@storybook/addon-ondevice-actions'],
51+
} as RNStorybookConfig
52+
}
53+
export default config

0 commit comments

Comments
 (0)