|
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' |
2 | 3 |
|
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 |
7 | 9 |
|
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