Skip to content

Commit

Permalink
Merge pull request #16752 from storybookjs/fix/15336-proper-relative-…
Browse files Browse the repository at this point in the history
…babelloader-webpack5

Addon-docs: Fix babel-loader resolution based on builder
  • Loading branch information
shilman authored Jan 7, 2022
2 parents 84ec2f0 + 64cdf45 commit 8a9e840
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions addons/docs/src/frameworks/common/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import remarkExternalLinks from 'remark-external-links';

// @ts-ignore
import { createCompiler } from '@storybook/csf-tools/mdx';

const resolvedBabelLoader = require.resolve('babel-loader', {
paths: [require.resolve('@storybook/builder-webpack4')], // FIXME!!!
});
import type { Options } from '@storybook/core-common';

// for frameworks that are not working with react, we need to configure
// the jsx to transpile mdx, for now there will be a flag for that
Expand All @@ -34,8 +31,23 @@ function createBabelOptions({ babelOptions, mdxBabelOptions, configureJSX }: Bab
};
}

export function webpack(webpackConfig: any = {}, options: any = {}) {
export async function webpack(
webpackConfig: any = {},
options: Options &
BabelParams & { sourceLoaderOptions: any; transcludeMarkdown: boolean } & Parameters<
typeof createCompiler
>[0]
) {
const { builder = 'webpack4' } = await options.presets.apply<{ builder: any }>('core', {} as any);

const resolvedBabelLoader = require.resolve('babel-loader', {
paths: builder.match(/(webpack4|webpack5)/)
? [require.resolve(`@storybook/builder-${builder}`)]
: [builder],
});

const { module = {} } = webpackConfig;

// it will reuse babel options that are already in use in storybook
// also, these babel options are chained with other presets.
const {
Expand Down

0 comments on commit 8a9e840

Please sign in to comment.