@storybook/react-native
Version:
A better way to develop React Native Components for your app
120 lines (118 loc) • 3.66 kB
TypeScript
/**
* Minimal compiler types for webpack/rspack compatibility.
* We define these inline to avoid requiring @rspack/core or webpack as dependencies.
*/
interface Compiler {
options: {
resolve: {
alias?: Record<string, string | false>;
};
};
hooks: {
beforeCompile: {
tapPromise: (name: string, fn: () => Promise<void>) => void;
};
};
webpack: {
NormalModuleReplacementPlugin: new (pattern: RegExp, fn: (resource: {
request?: string;
}) => void) => {
apply: (compiler: Compiler) => void;
};
};
}
/**
* Options for configuring WebSockets used for syncing storybook instances or sending events to storybook.
*/
interface WebsocketsOptions {
/**
* The port WebSocket server will listen on. Defaults to 7007.
*/
port?: number;
/**
* The host WebSocket server will bind to. Defaults to 'localhost'.
*/
host?: string;
}
/**
* Options for configuring the Storybook Repack plugin.
*/
interface StorybookPluginOptions {
/**
* The path to the Storybook config folder. Defaults to './.rnstorybook'.
*/
configPath?: string;
/**
* If false, strips Storybook from the bundle. Defaults to true.
*/
enabled?: boolean;
/**
* WebSocket configuration for syncing storybook instances or sending events to storybook.
* When set to 'auto', uses port 7007 and auto-detects the host LAN IP address.
*/
websockets?: WebsocketsOptions | 'auto';
/**
* Whether to use JavaScript files for Storybook configuration instead of TypeScript.
* When true, generates storybook.requires.js instead of storybook.requires.ts.
* Defaults to false.
*/
useJs?: boolean;
/**
* Whether to include doc tools in the storybook.requires file.
* Doc tools provide additional documentation features. Defaults to true.
*/
docTools?: boolean;
/**
* Whether to use lite mode for the storybook. In lite mode, the default storybook UI
* is mocked out so you don't need to install all its dependencies like reanimated etc.
* Defaults to false.
*/
liteMode?: boolean;
}
/**
* Repack/Rspack plugin for React Native Storybook.
*
* Provides equivalent functionality to the Metro {@link withStorybook} wrapper:
* - Auto-generates `storybook.requires.ts` before compilation
* - Starts a WebSocket channel server for remote control / syncing
* - Supports `enabled: false` to strip Storybook from the bundle
* - Supports `liteMode` to mock out the full Storybook UI
*
* @example
* ```javascript
* import { StorybookPlugin } from '@storybook/react-native/repack/withStorybook';
*
* // In your rspack.config.mjs plugins array:
* new StorybookPlugin({
* enabled: true,
* websockets: 'auto',
* })
* ```
*
* @example
* ```javascript
* // Disable Storybook in production builds:
* new StorybookPlugin({
* enabled: process.env.STORYBOOK_ENABLED !== 'false',
* websockets: 'auto',
* })
* ```
*/
declare class StorybookPlugin {
private options;
private generated;
private serverStarted;
constructor(options?: StorybookPluginOptions);
apply(compiler: Compiler): void;
/**
* When enabled: generate storybook.requires, optionally start websocket server,
* and set up liteMode aliases.
*/
private applyEnabled;
/**
* When disabled: redirect all Storybook imports to empty modules,
* and replace the config folder index with a stub component.
*/
private applyDisabled;
}
export { StorybookPlugin, type StorybookPluginOptions };