Webpack 4-based builder for Storybook that provides framework-agnostic build engine for preview iframe compilation and bundling.
91
Core build functionality for development and production modes, providing webpack compilation with generator-based interruption support, progress reporting, and Express middleware integration.
Starts a development server with hot module replacement and webpack dev middleware.
/**
* Starts development server with hot reloading and webpack dev middleware
* @param options - Builder start options including router and Storybook options
* @returns Promise resolving to build result with bail function and stats
*/
function start(options: BuilderStartOptions): Promise<BuilderStartResult>;
interface BuilderStartOptions {
/** High-resolution time for performance tracking */
startTime?: ReturnType<typeof process.hrtime>;
/** Storybook configuration options */
options: Options;
/** Express router for middleware mounting */
router: any;
}
interface BuilderStartResult {
/** Function to stop the build process and clean up resources */
bail: () => Promise<void>;
/** Webpack compilation statistics */
stats: Stats;
/** Total build time measurement */
totalTime: ReturnType<typeof process.hrtime>;
}Usage Examples:
import { start } from "@storybook/builder-webpack4";
import express from "express";
const app = express();
const router = express.Router();
const startResult = await start({
startTime: process.hrtime(),
options: {
configType: 'DEVELOPMENT',
outputDir: './storybook-static',
configDir: '.storybook',
presets: presetManager,
framework: 'react',
// ... other options
},
router,
});
// Mount the router with webpack middleware
app.use(router);
// Later, stop the build process
await startResult.bail();Builds production version with webpack compilation and optimization.
/**
* Builds production version with webpack compilation and optimization
* @param options - Builder build options with Storybook configuration
* @returns Promise resolving to webpack Stats object
*/
function build(options: BuilderBuildOptions): Promise<BuilderBuildResult>;
interface BuilderBuildOptions {
/** High-resolution time for performance tracking */
startTime?: ReturnType<typeof process.hrtime>;
/** Storybook configuration options */
options: Options;
}
interface BuilderBuildResult extends Stats {
/** Webpack compilation statistics including errors and warnings */
}Usage Examples:
import { build } from "@storybook/builder-webpack4";
const buildResult = await build({
startTime: process.hrtime(),
options: {
configType: 'PRODUCTION',
outputDir: './storybook-static',
configDir: '.storybook',
presets: presetManager,
framework: 'react',
quiet: false,
// ... other options
},
});
if (buildResult.hasErrors()) {
console.error('Build failed with errors:', buildResult.toJson().errors);
} else {
console.log('Build completed successfully');
}Stops the build process and cleans up resources including webpack compilation and middleware.
/**
* Stops build process and cleans up resources
* Forces termination of webpack compilation and dev middleware
* @returns Promise that resolves when cleanup is complete
*/
function bail(): Promise<void>;Usage Examples:
import { bail } from "@storybook/builder-webpack4";
// Stop any running build process
await bail();
console.log('Build process stopped and resources cleaned up');Webpack instance executor providing access to webpack compiler with version checking.
/**
* Executor for obtaining webpack instance with version validation
*/
const executor: {
/**
* Gets webpack instance from presets or uses default webpack 4
* @param options - Storybook options with presets
* @returns Promise resolving to webpack instance
*/
get(options: Options): Promise<typeof webpack>;
};Usage Examples:
import { executor } from "@storybook/builder-webpack4";
const webpackInstance = await executor.get(storybookOptions);
const compiler = webpackInstance(webpackConfig);Additional utility functions for error handling and stats generation.
/**
* Creates webpack Stats object from error string for consistent error handling
* @param err - Error message string
* @returns Stats object with error information
*/
function makeStatsFromError(err: string): Stats;Usage Examples:
import { makeStatsFromError } from "@storybook/builder-webpack4";
const errorStats = makeStatsFromError('Webpack compilation failed');
console.log(errorStats.toJson().errors); // ['Webpack compilation failed']The builder functions implement comprehensive error handling:
debugWebpack option is enabled, full webpack stats are available for debuggingInstall with Tessl CLI
npx tessl i tessl/npm-storybook--builder-webpack4evals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10