CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-storybook--cli

Storybook CLI: Develop, document, and test UI components in isolation

Pending
Overview
Eval results
Files

core-commands.mddocs/

Core Commands

Essential daily-use commands for developing and building Storybook projects. These commands from the core storybook package provide the fundamental development workflow operations.

Capabilities

Development Server

Start Storybook development server with hot reloading and interactive features.

storybook dev [options]

Options:
  -p, --port <number>              Port to run Storybook (default: auto-detected)
  -h, --host <string>              Host to run Storybook
  -c, --config-dir <dir-name>      Directory where to load Storybook configurations from
  --https                          Serve Storybook over HTTPS
  --ssl-ca <ca>                    Provide SSL certificate authority (array)
  --ssl-cert <cert>                Provide SSL certificate (required with --https)
  --ssl-key <key>                  Provide SSL key (required with --https)
  --smoke-test                     Exit after successful start
  --ci                            CI mode (skip interactive prompts, don't open browser)
  --no-open                       Do not open Storybook automatically in the browser
  --quiet                         Suppress verbose build output
  --no-version-updates            Suppress update check
  --debug-webpack                 Display final webpack configurations for debugging
  --webpack-stats-json [directory] Write Webpack stats JSON to disk
  --stats-json [directory]        Write stats JSON to disk
  --preview-url <string>          Disables default storybook preview, use your own
  --force-build-preview           Build preview iframe even with --preview-url
  --docs                          Build a documentation-only site using addon-docs
  --exact-port                    Exit early if desired port is not available
  --initial-path [path]           URL path to append when visiting Storybook initially
  --preview-only                  Use the preview without the manager UI

Usage Examples:

# Start development server on default port
storybook dev

# Start on specific port and host
storybook dev --port 8080 --host 0.0.0.0

# Start with HTTPS
storybook dev --https --ssl-cert ./cert.pem --ssl-key ./key.pem

# Start in CI mode (no browser, non-interactive)
storybook dev --ci --smoke-test

# Start with docs-only mode
storybook dev --docs

# Start with custom config directory
storybook dev --config-dir ./custom-storybook

# Debug webpack configuration
storybook dev --debug-webpack --webpack-stats-json

Production Build

Build Storybook for production deployment as static files.

storybook build [options]

Options:
  -o, --output-dir <dir-name>      Directory where to store built files
  -c, --config-dir <dir-name>      Directory where to load Storybook configurations from
  --quiet                          Suppress verbose build output
  --debug-webpack                  Display final webpack configurations for debugging
  --webpack-stats-json [directory] Write Webpack stats JSON to disk
  --stats-json [directory]         Write stats JSON to disk
  --preview-url <string>           Disables default storybook preview, use your own
  --force-build-preview            Build preview iframe even with --preview-url
  --docs                           Build a documentation-only site using addon-docs
  --test                           Build stories optimized for testing purposes
  --preview-only                   Use the preview without the manager UI

Usage Examples:

# Build to default output directory (storybook-static)
storybook build

# Build to custom output directory
storybook build --output-dir ./dist/storybook

# Build docs-only site
storybook build --docs

# Build for testing (optimized for test runners)
storybook build --test

# Build with custom config directory
storybook build --config-dir ./custom-storybook

# Build with webpack stats for analysis
storybook build --webpack-stats-json ./webpack-stats

# Quiet build (minimal output)
storybook build --quiet

Index Generation

Generate story index for external tools and integrations.

storybook index [options]

Options:
  -o, --output-file <file-name>    JSON file to output index
  -c, --config-dir <dir-name>      Directory where to load Storybook configurations from
  --quiet                          Suppress verbose build output

Usage Examples:

# Generate index to default file
storybook index

# Generate index to custom file
storybook index --output-file ./stories-index.json

# Generate index with custom config directory
storybook index --config-dir ./custom-storybook --output-file ./index.json

Programmatic Usage

For programmatic usage, import functions from the core server package:

import { 
  buildDevStandalone, 
  buildStaticStandalone, 
  buildIndex,
  buildIndexStandalone 
} from "storybook/internal/core-server";

/**
 * Start development server programmatically
 * @param options - Development server configuration options
 * @returns Promise with server connection details
 */
function buildDevStandalone(
  options: CLIOptions & LoadOptions & BuilderOptions & {
    storybookVersion?: string;
    previewConfigPath?: string;
  }
): Promise<{ port: number; address: string; networkAddress: string }>;

/**
 * Build Storybook for production programmatically
 * @param options - Build configuration options
 * @returns Promise that resolves when build is complete
 */
function buildStaticStandalone(options: BuildStaticStandaloneOptions): Promise<void>;

/**
 * Generate story index programmatically
 * @param options - Index generation options
 * @returns Promise with the generated story index
 */
function buildIndex(options: BuildIndexOptions): Promise<StoryIndex>;

/**
 * Generate and write story index to file programmatically
 * @param options - Index generation and output options
 * @returns Promise that resolves when index is written
 */
function buildIndexStandalone(
  options: BuildIndexOptions & { outputFile: string }
): Promise<void>;

Usage Examples:

import { 
  buildDevStandalone, 
  buildStaticStandalone, 
  buildIndex,
  buildIndexStandalone 
} from "storybook/internal/core-server";

// Start development server
const result = await buildDevStandalone({
  configDir: './.storybook',
  port: 6006,
  host: 'localhost',
  packageJson: require('./package.json')
});
console.log(`Storybook started on port ${result.port}`);

// Build for production
await buildStaticStandalone({
  configDir: './.storybook',
  outputDir: './storybook-static',
  quiet: false,
  packageJson: require('./package.json')
});

// Generate story index
const index = await buildIndex({
  configDir: './.storybook',
  packageJson: require('./package.json')
});

// Generate and write story index to file
await buildIndexStandalone({
  configDir: './.storybook', 
  outputFile: './stories.json',
  packageJson: require('./package.json')
});

Types

interface CLIOptions extends CLIBaseOptions {
  port?: number;
  ignorePreview?: boolean;
  previewUrl?: string;
  forceBuildPreview?: boolean;
  host?: string;
  initialPath?: string;
  exactPort?: boolean;
  https?: boolean;
  sslCa?: string[];
  sslCert?: string;
  sslKey?: string;
  smokeTest?: boolean;
  managerCache?: boolean;
  open?: boolean;
  ci?: boolean;
  versionUpdates?: boolean;
  docs?: boolean;
  test?: boolean;
  debugWebpack?: boolean;
  webpackStatsJson?: string | boolean;
  statsJson?: string | boolean;
  outputDir?: string;
  previewOnly?: boolean;
}

interface CLIBaseOptions {
  disableTelemetry?: boolean;
  enableCrashReports?: boolean;
  configDir?: string;
  loglevel?: string;
  quiet?: boolean;
}

interface LoadOptions {
  packageJson?: PackageJson;
  outputDir?: string;
  configDir?: string;
  cacheKey?: string;
  ignorePreview?: boolean;
  extendServer?: (server: HttpServer) => void;
}

interface BuilderOptions {
  configType?: "DEVELOPMENT" | "PRODUCTION";
  ignorePreview?: boolean;
  cache?: FileSystemCache;
  configDir: string;
  docsMode?: boolean;
  features?: StorybookConfigRaw["features"];
  versionCheck?: VersionCheck;
  disableWebpackDefaults?: boolean;
  serverChannelUrl?: string;
}

type BuildStaticStandaloneOptions = CLIOptions & LoadOptions & BuilderOptions & { 
  outputDir: string;
};

type BuildIndexOptions = CLIOptions & LoadOptions & BuilderOptions;

interface CLIIndexOptions extends CLIBaseOptions {
  configDir?: string;
  outputFile?: string;
}

interface StoryIndex {
  v: number;
  entries: Record<string, StoryIndexEntry>;
}

interface StoryIndexEntry {
  id: string;
  title: string;
  name: string;
  importPath: string;
  type: "docs" | "story";
  tags?: string[];
}

Environment Variables

All commands support environment variable configuration:

# Port configuration
SBCONFIG_PORT=8080 storybook dev

# Host configuration  
SBCONFIG_HOSTNAME=0.0.0.0 storybook dev

# Config directory
SBCONFIG_CONFIG_DIR=./custom-storybook storybook dev

# Output directory
SBCONFIG_OUTPUT_DIR=./dist storybook build

# CI mode
CI=true storybook dev

# Output file for index
SBCONFIG_OUTPUT_FILE=./stories.json storybook index

Install with Tessl CLI

npx tessl i tessl/npm-storybook--cli

docs

addon-management.md

automigration.md

code-migration.md

core-commands.md

development-tools.md

diagnostics.md

index.md

initialization.md

version-management.md

tile.json