UNPKG

2.09 kBTypeScriptView Raw
1import type { InputConfigT } from 'metro-config';
2
3/**
4 * Options for configuring WebSockets used for syncing storybook instances or sending events to storybook.
5 */
6interface WebsocketsOptions {
7 /**
8 * The port WebSocket server will listen on. Defaults to 7007.
9 */
10 port?: number;
11
12 /**
13 * The host WebSocket server will bind to. Defaults to 'localhost'.
14 */
15 host?: string;
16}
17
18/**
19 * Options for configuring Storybook with React Native.
20 */
21interface WithStorybookOptions {
22 /**
23 * The path to the Storybook config folder. Defaults to './.storybook'.
24 */
25 configPath?: string;
26
27 /**
28 * Whether Storybook is enabled. Defaults to true.
29 */
30 enabled?: boolean;
31
32 /**
33 * WebSocket configuration for syncing storybook instances or sending events to storybook.
34 */
35 websockets?: WebsocketsOptions;
36
37 /**
38 * Whether to use JavaScript files for Storybook configuration instead of TypeScript. Defaults to false.
39 */
40 useJs?: boolean;
41
42 /**
43 * If enabled is false and onDisabledRemoveStorybook is true, we will attempt to remove storybook from the js bundle.
44 */
45 onDisabledRemoveStorybook?: boolean;
46}
47
48/**
49 * Configures Metro bundler to work with Storybook in React Native.
50 * This function wraps a Metro configuration to enable Storybook usage.
51 *
52 * @param config - The Metro bundler configuration to be modified.
53 * @param options - Options to customize the Storybook configuration.
54 * @returns The modified Metro configuration.
55 *
56 * @example
57 * const { getDefaultConfig } = require('expo/metro-config');
58 * const withStorybook = require('@storybook/react-native/metro/withStorybook');
59 * const path = require('path');
60 *
61 * const projectRoot = __dirname;
62 * const config = getDefaultConfig(projectRoot);
63 *
64 * module.exports = withStorybook(config, {
65 * enabled: true,
66 * configPath: path.resolve(projectRoot, './.storybook'),
67 * websockets: { port: 7007, host: 'localhost' },
68 * useJs: false,
69 * onDisabledRemoveStorybook: true,
70 * });
71 */
72export function withStorybook(config: InputConfigT, options?: WithStorybookOptions): InputConfigT;