From facbcfc7aeb236ff8b2016d5559f70c78bd59a70 Mon Sep 17 00:00:00 2001 From: Guillaume Clochard Date: Thu, 29 Aug 2024 22:00:04 +0200 Subject: [PATCH] pass framework options docs to addon-docs --- README.md | 31 +++++++++++++++++++ .../src/preview/iframe-rsbuild.config.ts | 5 +-- packages/builder-rsbuild/src/types.ts | 4 +++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 7950432..c61f795 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,37 @@ const config = { export default config ``` +#### `addonDocs` + +- Type: `object` +- Default: `undefined` + +`@storybook/addon-docs` webpack options. The builder uses `@storybook/addon-docs` internally, and accepts the passing [some options](https://github.com/storybookjs/storybook/tree/next/code/addons/docs#preset-options) via `addonDocs`. + +```js +// .storybook/main.mjs +import remarkGfm from 'remark-gfm'; + +const config = { + framework: { + name: 'storybook-react-rsbuild', + options: { + builder: { + addonDocs: { + mdxPluginOptions: { + mdxCompileOptions: { + remarkPlugins: [remarkGfm], + }, + }, + }, + }, + }, + }, +} + +export default config +``` + ### Customize builder's Rsbuild config You can also override the merged Rsbuild config: diff --git a/packages/builder-rsbuild/src/preview/iframe-rsbuild.config.ts b/packages/builder-rsbuild/src/preview/iframe-rsbuild.config.ts index cc3eb22..8299e15 100644 --- a/packages/builder-rsbuild/src/preview/iframe-rsbuild.config.ts +++ b/packages/builder-rsbuild/src/preview/iframe-rsbuild.config.ts @@ -57,7 +57,9 @@ export type RsbuildBuilderOptions = Options & { export default async ( options: RsbuildBuilderOptions, ): Promise => { - const appliedDocsWebpack = await docsWebpack({}, options) + const { rsbuildConfigPath, addonDocs } = + await getBuilderOptions(options) + const appliedDocsWebpack = await docsWebpack({}, { ...options, ...addonDocs }) const { outputDir = join('.', 'public'), quiet, @@ -102,7 +104,6 @@ export default async ( presets.apply('tags', {}), ]) - const { rsbuildConfigPath } = await getBuilderOptions(options) const stories = normalizeStories(nonNormalizedStories, { configDir: options.configDir, workingDir, diff --git a/packages/builder-rsbuild/src/types.ts b/packages/builder-rsbuild/src/types.ts index caea197..23ad126 100644 --- a/packages/builder-rsbuild/src/types.ts +++ b/packages/builder-rsbuild/src/types.ts @@ -47,6 +47,10 @@ export type BuilderOptions = { * Which environment to use from the Rsbuild config. */ environment?: string + /** + * @storybook/addon-docs options + */ + addonDocs?: any } export interface BuilderResult extends BuilderResultBase {