Skip to content

Commit

Permalink
Allow passing @storybook/addon-docs options via framework options (#78)
Browse files Browse the repository at this point in the history
  • Loading branch information
guillaumewuip authored Sep 2, 2024
1 parent 6b86884 commit 028b3d3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions packages/builder-rsbuild/src/preview/iframe-rsbuild.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ export type RsbuildBuilderOptions = Options & {
export default async (
options: RsbuildBuilderOptions,
): Promise<RsbuildConfig> => {
const appliedDocsWebpack = await docsWebpack({}, options)
const { rsbuildConfigPath, addonDocs } =
await getBuilderOptions<BuilderOptions>(options)
const appliedDocsWebpack = await docsWebpack({}, { ...options, ...addonDocs })
const {
outputDir = join('.', 'public'),
quiet,
Expand Down Expand Up @@ -102,7 +104,6 @@ export default async (
presets.apply('tags', {}),
])

const { rsbuildConfigPath } = await getBuilderOptions<BuilderOptions>(options)
const stories = normalizeStories(nonNormalizedStories, {
configDir: options.configDir,
workingDir,
Expand Down
4 changes: 4 additions & 0 deletions packages/builder-rsbuild/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 028b3d3

Please sign in to comment.