Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed May 17, 2024
1 parent 04378b7 commit 5cb8045
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 2 additions & 3 deletions code/addons/docs/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,10 @@ async function webpack(
module: {
...module,
rules: [
...(module.rules || []),
...(csfPluginOptions
? [
{
test: /\.stories\.[tj]sx?$/,
enforce: 'post',
test: /(?<!node_modules.*)\.(story|stories)\.[tj]sx?$/,
use: [
{
loader: require.resolve('./csf-loader'),
Expand All @@ -111,6 +109,7 @@ async function webpack(
},
]
: []),
...(module.rules || []),
{
test: /\.mdx$/,
exclude: /(stories|story)\.mdx$/,
Expand Down
2 changes: 1 addition & 1 deletion code/frameworks/react-vite/src/plugins/react-docgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function reactDocgen({

return {
code: s.toString(),
map: s.generateMap(),
map: s.generateMap({ hires: true, source: id }),
};
} catch (e: any) {
// Ignore the error when react-docgen cannot find a react component
Expand Down
7 changes: 2 additions & 5 deletions code/presets/react-webpack/src/loaders/react-docgen-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ let matchPath: TsconfigPaths.MatchPath | undefined;

export default async function reactDocgenLoader(
this: LoaderContext<{ debug: boolean }>,
source: string
source: string,
map: any
) {
const callback = this.async();
// get options
Expand Down Expand Up @@ -115,10 +116,6 @@ export default async function reactDocgenLoader(
}
});

const map = magicString.generateMap({
includeContent: true,
source: this.resourcePath,
});
callback(null, magicString.toString(), map);
} catch (error: any) {
if (error.code === ERROR_CODES.MISSING_DEFINITION) {
Expand Down
16 changes: 12 additions & 4 deletions scripts/tasks/sandbox-parts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,18 @@ function addEsbuildLoaderToStories(mainConfig: ConfigFile) {
],
},
// Ensure no other loaders from the framework apply
...config.module.rules.map(rule => ({
...rule,
exclude: [/\\/template-stories\\//].concat(rule.exclude || []),
})),
...config.module.rules.map(rule => {
// The csf loader is responsible to add metadata to CSF files (e.g. extracting JSON comments)
if(typeof rule === 'object' && rule?.use?.[0]?.loader?.includes('csf-loader')) {
return rule;
}
return ({
...rule,
exclude: [/\\/template-stories\\//].concat(rule.exclude || []),
})
}),
],
},
})`;
Expand Down

0 comments on commit 5cb8045

Please sign in to comment.