Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow passing @storybook/addon-docs options via framework options #78

Merged
merged 1 commit into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't find a way to do better than this given the typings of @storybook/addon-docs/dist/preset:

import { PresetProperty, Options } from 'storybook/internal/types';

declare const addons: PresetProperty<'addons'>;
declare const viteFinal: (config: any, options: Options) => Promise<any>;
declare const webpackX: any;
declare const docsX: any;
/**
 * If the user has not installed react explicitly in their project,
 * the resolvedReact preset will not be set.
 * We then set it here in addon-docs to use addon-docs's react version that always exists.
 * This is just a fallback that never overrides the existing preset,
 * but ensures that there is always a resolved react.
 */
declare const resolvedReact: (existing: any) => Promise<{
    react: any;
    reactDom: any;
    mdx: any;
}>;
declare const optimizeViteDeps: string[];

export { addons, docsX as docs, optimizeViteDeps, resolvedReact, viteFinal, webpackX as webpack };

No type export for the options directly, and thewebpack export is any, preventing us to extract it's parameters.

}

export interface BuilderResult extends BuilderResultBase {
Expand Down