diff --git a/code/lib/builder-vite/src/plugins/mdx-plugin.ts b/code/lib/builder-vite/src/plugins/mdx-plugin.ts index 30285c1b7048..2527921004fd 100644 --- a/code/lib/builder-vite/src/plugins/mdx-plugin.ts +++ b/code/lib/builder-vite/src/plugins/mdx-plugin.ts @@ -1,3 +1,4 @@ +import type { Options } from '@storybook/types'; import type { Plugin } from 'vite'; import { createFilter } from 'vite'; @@ -18,7 +19,7 @@ function injectRenderer(code: string) { * * @see https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/recipes.md#csf-stories-with-arbitrary-mdx */ -export function mdxPlugin(): Plugin { +export function mdxPlugin(options: Options): Plugin { let reactRefresh: Plugin | undefined; const include = /\.mdx?$/; const filter = createFilter(include); @@ -41,12 +42,23 @@ export function mdxPlugin(): Plugin { reactRefresh = reactRefreshPlugins.find((p) => p.transform); }, - async transform(src, id, options) { + async transform(src, id, transformOptions) { if (!filter(id)) return undefined; const { compile } = await import('@storybook/mdx2-csf'); - const mdxCode = String(await compile(src, { skipCsf: !isStorybookMdx(id) })); + const mdxLoaderOptions = await options.presets.apply('mdxLoaderOptions', { + mdxCompileOptions: { + providerImportSource: '@storybook/addon-docs/mdx-react-shim', + }, + }); + + const mdxCode = String( + await compile(src, { + skipCsf: !isStorybookMdx(id), + ...mdxLoaderOptions, + }) + ); const modifiedCode = injectRenderer(mdxCode); @@ -56,7 +68,7 @@ export function mdxPlugin(): Plugin { // It's safe to disable this, because we know it'll be there, since we added it ourselves. // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const result = await transform!.call(this, modifiedCode, `${id}.jsx`, options); + const result = await transform!.call(this, modifiedCode, `${id}.jsx`, transformOptions); if (!result) return modifiedCode; diff --git a/code/lib/builder-vite/src/vite-config.ts b/code/lib/builder-vite/src/vite-config.ts index 464373b6f7cd..5917c6f0e3a0 100644 --- a/code/lib/builder-vite/src/vite-config.ts +++ b/code/lib/builder-vite/src/vite-config.ts @@ -75,7 +75,7 @@ export async function pluginConfig(options: ExtendedOptions) { const plugins = [ codeGeneratorPlugin(options), // sourceLoaderPlugin(options), - mdxPlugin(), + mdxPlugin(options), injectExportOrderPlugin, stripStoryHMRBoundary(), { diff --git a/code/presets/react-webpack/package.json b/code/presets/react-webpack/package.json index 242903d1bca6..f3e4e01dd3df 100644 --- a/code/presets/react-webpack/package.json +++ b/code/presets/react-webpack/package.json @@ -88,15 +88,12 @@ "semver": "^7.3.7" }, "devDependencies": { - "@types/util-deprecate": "^1.0.0", "typescript": "~4.9.3" }, "peerDependencies": { "@babel/core": "^7.11.5", - "jest-specific-snapshot": "^7.0.0", "react": "^16.8.0 || ^17.0.0 || ^18.0.0", "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0", - "require-from-string": "^2.0.2", "webpack": "5" }, "peerDependenciesMeta": { diff --git a/code/yarn.lock b/code/yarn.lock index a43b04d31808..a32667a14149 100644 --- a/code/yarn.lock +++ b/code/yarn.lock @@ -6788,7 +6788,6 @@ __metadata: "@storybook/react-docgen-typescript-plugin": 1.0.2-canary.6.9d540b91e815f8fc2f8829189deb00553559ff63.0 "@types/node": ^16.0.0 "@types/semver": ^7.3.4 - "@types/util-deprecate": ^1.0.0 babel-plugin-add-react-displayname: ^0.0.5 babel-plugin-react-docgen: ^4.2.1 fs-extra: ^9.0.1 @@ -6797,10 +6796,8 @@ __metadata: typescript: ~4.9.3 peerDependencies: "@babel/core": ^7.11.5 - jest-specific-snapshot: ^7.0.0 react: ^16.8.0 || ^17.0.0 || ^18.0.0 react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0 - require-from-string: ^2.0.2 webpack: 5 peerDependenciesMeta: "@babel/core":