-
Notifications
You must be signed in to change notification settings - Fork 8
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
Support for .md / .mdx files in storybook #29
Comments
storybook-rsbuild's configuration is a little complex so for now you had to write the import { mergeRsbuildConfig } from '@rsbuild/core'
import type { StorybookConfig } from 'storybook-react-rsbuild'
import { join, dirname } from 'path'
/**
* This function is used to resolve the absolute path of a package.
* It is needed in projects that use Yarn PnP or are set up within a monorepo.
*/
function getAbsolutePath(value: string): any {
return dirname(require.resolve(join(value, 'package.json')))
}
const config: StorybookConfig = {
stories: ['../src/**/*.mdx', '../src/**/*.stories.@(js|jsx|mjs|ts|tsx)'],
addons: [
getAbsolutePath('@storybook/addon-onboarding'),
getAbsolutePath('@storybook/addon-links'),
getAbsolutePath('@storybook/addon-essentials'),
getAbsolutePath('@chromatic-com/storybook'),
getAbsolutePath('@storybook/addon-interactions'),
],
framework: {
name: getAbsolutePath('storybook-react-rsbuild'),
options: {},
},
docs: {
autodocs: 'tag',
},
typescript: {
reactDocgen: 'react-docgen',
check: true,
},
rsbuildFinal: (config) => {
return mergeRsbuildConfig(config, {
tools: {
+ rspack(config, { addRules, mergeConfig }) {
+ return mergeConfig(config, {
+ module: {
+ rules: [
+ {
+ test: /\.md$/,
+ type: 'asset/source',
+ },
+ ],
+ },
})
},
},
})
},
}
export default config |
Well, I'm importing it plain text to render it within an .mdx file. So that should work. Can't test it though until #30 is addressed ;) Unless I'd set up a separate project just to test this. |
So when importing and using a |
webpack & SB7, yes. But the import was *.md?raw but I think that results in pretty much the same. |
I'll test does it works on webpack and SB8 then align with it. |
I am migrating my project from webpack to rsbuild and am currently in the process of trying to make storybook work with the adapted setup. Using this library, I'd have expected it to support .mdx files out of the box, as it's pretty standard for storybook.
So I started out with a simple configuration without any custom .md(x) configuration. Doesn't complain about
.mdx
, but about my.md
import within an.mdx
file. Since in webpack I have been dealing with.md
files by adding a rule to treat.md
as typeasset/source
, I thought I could simply do that here too, but to no avail. I've also used this rule successfully with rsbuild when referencing.md
from within.ts
files.My suspicion is, that this rule is not applied within for
.mdx
files and therefore it still doesn't know what to do with that.md
import in my.mdx
file.Did I simply miss some additinoal config, or is this not yet supported?
I also did try using the
pluginMdx()
, but that only made things worse (weird errors on.mdx
files that weren't complaining without the plugin.The text was updated successfully, but these errors were encountered: