storybook.requires file that contains your story imports.
sb-rn-get-stories
Generates thestorybook.requires file by scanning your configured stories and creating the necessary imports.
Usage
Options
The path to your config folder relative to your project directory.This folder should contain your
main.ts and preview.ts files.Use a JavaScript file for
storybook.requires instead of TypeScript.When enabled, generates storybook.requires.js instead of storybook.requires.ts.Do not include doc tools in the
storybook.requires file.Doc tools provide additional documentation features like component metadata extraction.Host for WebSocket connections.The value
'auto' tells Storybook to use your local IP address.When
--host is provided, the WebSocket configuration is injected into the generated storybook.requires file.Port for WebSocket connections.Must be a valid port number (integer).
The
--port option must be used with --host to enable WebSocket configuration.Examples
Basic Generation
Generate the requires file with default settings:.rnstorybook/storybook.requires.ts by scanning the stories configured in .rnstorybook/main.ts.
Custom Config Path
Use a different config directory:JavaScript Output
Generate a JavaScript file instead of TypeScript:.rnstorybook/storybook.requires.js.
With WebSockets
Generate with WebSocket configuration:Without Doc Tools
Exclude doc tools to reduce bundle size:Complete Example
Generated File Structure
Thestorybook.requires file contains:
-
WebSocket Configuration (if provided):
-
Story Imports:
-
Configuration Exports:
Integration with Metro
You typically don’t need to run this command manually. The
withStorybook Metro wrapper automatically generates the file during bundling.- CI/CD pipelines: Pre-generate the requires file before building
- Version control: Commit the generated file to track changes
- Debugging: Manually regenerate the file to troubleshoot issues
Manual Regeneration
If you need to manually regenerate the file:package.json:
package.json
npm Scripts
Typical npm scripts for Storybook development:package.json
Error Handling
Invalid Port Number
If you provide an invalid port:Missing Config Directory
If the config path doesn’t exist:No Stories Found
If no stories match your configuration:main.ts stories configuration to ensure the globs match your story files.
Programmatic API
You can also use the generate function programmatically:Watch Mode
The CLI does not have a built-in watch mode. The
withStorybook Metro wrapper automatically regenerates the file when your stories change.TypeScript Support
The generated.ts file has full TypeScript support:
storybook.requires.ts