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

Vite: Move mdx-plugin from @storybook/builder-vite to @storybook/addon-docs #24166

Merged
merged 10 commits into from
Sep 22, 2023
4 changes: 3 additions & 1 deletion code/addons/docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,11 @@
"ts-dedent": "^2.0.0"
},
"devDependencies": {
"@rollup/pluginutils": "^5.0.2",
"react": "^16.14.0",
"react-dom": "^16.8.0",
"typescript": "~4.9.3"
"typescript": "~4.9.3",
"vite": "^4.0.4"
ndelangen marked this conversation as resolved.
Show resolved Hide resolved
},
"peerDependencies": {
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { Options } from '@storybook/types';
import type { Plugin } from 'vite';
import remarkSlug from 'remark-slug';
import remarkExternalLinks from 'remark-external-links';
import { createFilter } from 'vite';
import { createFilter } from '@rollup/pluginutils';
import { dirname, join } from 'path';

const isStorybookMdx = (id: string) => id.endsWith('stories.mdx') || id.endsWith('story.mdx');
Expand Down
9 changes: 9 additions & 0 deletions code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ export const addons: StorybookConfig['addons'] = [
require.resolve('@storybook/react-dom-shim/dist/preset'),
];

export const viteFinal = async (config: any, options: Options) => {
const { plugins = [] } = config;
const { mdxPlugin } = await import('./plugins/mdx-plugin');

plugins.push(mdxPlugin(options));

return config;
};

/*
* This is a workaround for https://github.com/Swatinem/rollup-plugin-dts/issues/162
* something down the dependency chain is using typescript namespaces, which are not supported by rollup-plugin-dts
Expand Down
6 changes: 0 additions & 6 deletions code/builders/builder-vite/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
"@storybook/client-logger": "workspace:*",
"@storybook/core-common": "workspace:*",
"@storybook/csf-plugin": "workspace:*",
"@storybook/mdx2-csf": "^1.0.0",
"@storybook/node-logger": "workspace:*",
"@storybook/preview": "workspace:*",
"@storybook/preview-api": "workspace:*",
Expand All @@ -59,8 +58,6 @@
"find-cache-dir": "^3.0.0",
"fs-extra": "^11.1.0",
"magic-string": "^0.30.0",
"remark-external-links": "^8.0.0",
"remark-slug": "^6.0.0",
"rollup": "^2.25.0 || ^3.3.0"
},
"devDependencies": {
Expand Down Expand Up @@ -96,9 +93,6 @@
"entries": [
"./src/index.ts"
],
"externals": [
"@storybook/mdx1-csf"
],
"platform": "node"
},
"gitHead": "e6a7fd8a655c69780bc20b9749c2699e44beae17"
Expand Down
1 change: 0 additions & 1 deletion code/builders/builder-vite/src/plugins/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export * from './inject-export-order-plugin';
export * from './mdx-plugin';
export * from './strip-story-hmr-boundaries';
export * from './code-generator-plugin';
export * from './csf-plugin';
Expand Down
2 changes: 0 additions & 2 deletions code/builders/builder-vite/src/vite-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
codeGeneratorPlugin,
csfPlugin,
injectExportOrderPlugin,
mdxPlugin,
stripStoryHMRBoundary,
externalGlobalsPlugin,
} from './plugins';
Expand Down Expand Up @@ -81,7 +80,6 @@ export async function pluginConfig(options: Options) {
const plugins = [
codeGeneratorPlugin(options),
await csfPlugin(options),
await mdxPlugin(options),
injectExportOrderPlugin,
stripStoryHMRBoundary(),
{
Expand Down
5 changes: 2 additions & 3 deletions code/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5905,6 +5905,7 @@ __metadata:
dependencies:
"@jest/transform": ^29.3.1
"@mdx-js/react": ^2.1.5
"@rollup/pluginutils": ^5.0.2
"@storybook/blocks": "workspace:*"
"@storybook/client-logger": "workspace:*"
"@storybook/components": "workspace:*"
Expand All @@ -5925,6 +5926,7 @@ __metadata:
remark-slug: ^6.0.0
ts-dedent: ^2.0.0
typescript: ~4.9.3
vite: ^4.0.4
peerDependencies:
react: ^16.8.0 || ^17.0.0 || ^18.0.0
react-dom: ^16.8.0 || ^17.0.0 || ^18.0.0
Expand Down Expand Up @@ -6530,7 +6532,6 @@ __metadata:
"@storybook/client-logger": "workspace:*"
"@storybook/core-common": "workspace:*"
"@storybook/csf-plugin": "workspace:*"
"@storybook/mdx2-csf": ^1.0.0
"@storybook/node-logger": "workspace:*"
"@storybook/preview": "workspace:*"
"@storybook/preview-api": "workspace:*"
Expand All @@ -6545,8 +6546,6 @@ __metadata:
fs-extra: ^11.1.0
glob: ^10.0.0
magic-string: ^0.30.0
remark-external-links: ^8.0.0
remark-slug: ^6.0.0
rollup: ^3.20.1
slash: ^5.0.0
typescript: ~4.9.3
Expand Down