UNPKG

storybook-builder-rsbuild

Version:
103 lines (97 loc) 4.52 kB
import * as rsbuildReal from '@rsbuild/core'; import { DevConfig, RsbuildConfig } from '@rsbuild/core'; import { BuilderResult as BuilderResult$1, Builder, Options, StorybookConfigRaw, TypescriptOptions as TypescriptOptions$1, NormalizedStoriesSpecifier } from 'storybook/internal/types'; import { PluginTypeCheckerOptions } from '@rsbuild/plugin-type-check'; type RsbuildStats = { toJson: (...args: any[]) => any; }; /** * Options for TypeScript usage within Storybook. */ interface TypescriptOptions extends TypescriptOptions$1 { /** * Configures `@rsbuild/plugin-type-check`, using `fork-ts-checker-webpack-plugin` under the hood. */ checkOptions?: PluginTypeCheckerOptions; } type RsbuildBuilder = Builder<RsbuildConfig, RsbuildStats>; type RsbuildFinal = (config: RsbuildConfig, options: Options) => RsbuildConfig | Promise<RsbuildConfig>; type StorybookConfigRsbuild = { rsbuildFinal?: RsbuildFinal; webpackAddons?: StorybookConfigRaw['addons']; }; type BuilderOptions = { /** * Path to rsbuild.config file, relative to CWD. */ rsbuildConfigPath?: string; /** * Pass-through Rsbuild `dev.lazyCompilation` options. */ lazyCompilation?: DevConfig['lazyCompilation']; /** * Enable Rspack's [persistent cache(experimental)](https://rspack.dev/config/experiments#experimentscache). * We continue to use the name `fsCache` here to maintain better compatibility with the webpack builder. */ fsCache?: boolean; /** * Which environment to use from the Rsbuild config. */ environment?: string; /** * @storybook/addon-docs options */ addonDocs?: any; }; interface BuilderResult extends BuilderResult$1 { stats?: Stats; } /** * Strips fields that are unsafe to inherit into the Storybook preview build. * * @internal For use by official Storybook Rsbuild packages only. This API is subject to change at * any time and should not be used in user configuration. */ declare const stripInheritedConfig: (config: RsbuildConfig, source: string) => string[]; /** * Re-assert Storybook core's intent to keep `node_modules` out of the stories * context. Core's `(?!.*node_modules)` guard relies on webpack's context * dropping `node_modules`; Rspack's `ContextModule` enumerates it, so a * dependency shipping `.stories.*` gets swept in. We append a separator-anchored * `webpackExclude` to every generated `webpackInclude`, except specifiers that * intentionally glob into `node_modules` (real segment or alternation branch) — * matching the webpack builder, which surfaces those. * * TODO: remove once the upstream Rspack fix ships in a released `@rspack/core` * — https://github.com/web-infra-dev/rspack/pull/14576. */ declare const excludeNodeModulesFromStoryContext: (importFnSource: string, stories: NormalizedStoriesSpecifier[]) => string; declare const getVirtualModules: (options: Options, isLazyCompilationActive: boolean) => Promise<{ virtualModules: Record<string, string>; entries: string[]; }>; type StatsOrMultiStats = Parameters<rsbuildReal.OnAfterBuildFn>[0]['stats']; type Stats = NonNullable<Exclude<StatsOrMultiStats, { stats: unknown[]; }>>; declare const printDuration: (startTime: [number, number]) => string; type BuilderStartOptions = Parameters<RsbuildBuilder['start']>['0']; declare const executor: { get: (options: Options) => Promise<typeof rsbuildReal>; }; declare const getConfig: RsbuildBuilder['getConfig']; declare function bail(): Promise<void>; /** * Returns a {@link ChangeDetectionAdapter} bound to the Rspack compiler created by `start()`. * * Storybook core only invokes this after `start()` has resolved, so `activeCompiler` is populated * in practice. The guard is defensive: it fails loudly on an unexpected call-before-start rather * than silently binding to an undefined compiler. */ declare const changeDetectionAdapter: NonNullable<RsbuildBuilder['changeDetectionAdapter']>; declare const start: RsbuildBuilder['start']; declare const build: ({ options }: BuilderStartOptions) => Promise<Stats>; declare const corePresets: string[]; declare const previewMainTemplate: () => string; export { bail, build, changeDetectionAdapter, corePresets, excludeNodeModulesFromStoryContext, executor, getConfig, getVirtualModules, previewMainTemplate, printDuration, start, stripInheritedConfig }; export type { BuilderOptions, BuilderResult, RsbuildBuilder, RsbuildFinal, Stats, StorybookConfigRsbuild, TypescriptOptions };