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

Addon Docs: Dynamically import rehype #29544

Merged
merged 1 commit into from
Dec 13, 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
5 changes: 3 additions & 2 deletions code/addons/docs/src/plugins/mdx-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import { dirname, join } from 'node:path';
import type { Options } from 'storybook/internal/types';

import { createFilter } from '@rollup/pluginutils';
import rehypeExternalLinks from 'rehype-external-links';
import rehypeSlug from 'rehype-slug';
import type { Plugin } from 'vite';

import type { CompileOptions } from '../compiler';
Expand All @@ -24,6 +22,9 @@ export async function mdxPlugin(options: Options): Promise<Plugin> {
const presetOptions = await presets.apply<Record<string, any>>('options', {});
const mdxPluginOptions = presetOptions?.mdxPluginOptions as CompileOptions;

const rehypeSlug = (await import('rehype-slug')).default;
const rehypeExternalLinks = (await import('rehype-external-links')).default;
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved

return {
name: 'storybook:mdx-plugin',
enforce: 'pre',
Expand Down
9 changes: 6 additions & 3 deletions code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import type { DocsOptions, Options, PresetProperty } from 'storybook/internal/ty

import type { CsfPluginOptions } from '@storybook/csf-plugin';

import rehypeExternalLinks from 'rehype-external-links';
import rehypeSlug from 'rehype-slug';

import type { CompileOptions } from './compiler';

/**
Expand Down Expand Up @@ -42,6 +39,9 @@ async function webpack(

const { csfPluginOptions = {}, mdxPluginOptions = {} } = options;

const rehypeSlug = (await import('rehype-slug')).default;
const rehypeExternalLinks = (await import('rehype-external-links')).default;

const mdxLoaderOptions: CompileOptions = await options.presets.apply('mdxLoaderOptions', {
...mdxPluginOptions,
mdxCompileOptions: {
Expand Down Expand Up @@ -175,6 +175,9 @@ export const viteFinal = async (config: any, options: Options) => {
const { plugins = [] } = config;
const { mdxPlugin } = await import('./plugins/mdx-plugin');

const rehypeSlug = (await import('rehype-slug')).default;
const rehypeExternalLinks = (await import('rehype-external-links')).default;
valentinpalkovic marked this conversation as resolved.
Show resolved Hide resolved

// Use the resolvedReact preset to alias react and react-dom to either the users version or the version shipped with addon-docs
const { react, reactDom, mdx } = await getResolvedReact(options);

Expand Down
Loading