Builder implemented with webpack5 and webpack5-compatible loaders/plugins/config, used by @storybook/core-server to build the manager UI
—
Intelligent caching system for manager builds and configurations to improve build performance by avoiding unnecessary rebuilds when configuration and files haven't changed.
Checks if a cached manager build can be reused based on configuration and file modification times.
/**
* Check if cached manager build can be reused
* @param cacheKey - Unique key identifying the cache entry
* @param options - Storybook configuration options with cache provider
* @param managerConfig - Current webpack configuration for comparison
* @returns Promise resolving to true if cache can be used, false otherwise
*/
function useManagerCache(
cacheKey: string,
options: Options,
managerConfig: Configuration
): Promise<boolean>;
interface Options {
/** Cache provider for storing/retrieving cached data */
cache: CacheProvider;
/** Path to Storybook configuration directory */
configDir: string;
/** Other Storybook options */
[key: string]: any;
}
interface CacheProvider {
/** Retrieve cached value by key */
get(key: string): Promise<string>;
/** Store value with key */
set(key: string, value: string): Promise<void>;
/** Check if cache entry exists */
fileExists(key: string): boolean;
/** Remove cache entry */
remove(key: string): Promise<void>;
}Usage Examples:
import { useManagerCache } from "@storybook/manager-webpack5/utils/manager-cache";
const cacheKey = `managerConfig-webpack5@${storybookVersion}`;
const canUseCache = await useManagerCache(cacheKey, options, webpackConfig);
if (canUseCache) {
console.log('Using cached manager build');
// Skip build process
} else {
console.log('Cache miss, rebuilding manager');
// Proceed with build
}The cache system checks several factors to determine if a cached build is valid:
main.(m)js|ts - Already handled separatelypreview.(m)js|ts - Only affects preview, not managerpreview-head.html - Only affects preview, not managerRemoves cached manager build data when cache invalidation is needed.
/**
* Remove cached manager build data
* @param cacheKey - Unique key identifying the cache entry to remove
* @param options - Storybook configuration options with cache provider
* @returns Promise resolving to true if cache was cleared, false if no cache existed
*/
function clearManagerCache(cacheKey: string, options: Options): Promise<boolean>;Usage Examples:
import { clearManagerCache } from "@storybook/manager-webpack5/utils/manager-cache";
// Clear cache when configuration changes significantly
const wasCleared = await clearManagerCache(cacheKey, options);
if (wasCleared) {
console.log('Cleared cached manager configuration');
} else {
console.log('No cached configuration to clear');
}Cache keys are typically generated using a combination of:
Example:
const packageFile = await findUp('package.json', { cwd: __dirname });
const { version: storybookVersion } = await fs.readJSON(packageFile);
const cacheKey = `managerConfig-webpack5@${storybookVersion}`;The cache stores data in the following format:
{timestamp}_{serialized_config}Where:
timestamp: ISO timestamp of when the cache was createdserialized_config: JSON-serialized webpack configuration (excluding the cache property)The caching system provides significant performance improvements:
The caching system integrates with:
Install with Tessl CLI
npx tessl i tessl/npm-storybook--manager-webpack5