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: Fix babel-loader resolution based on builder #16752

Merged
merged 4 commits into from
Jan 7, 2022
Merged
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
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