Merge pull request #17320 from storybookjs/fix-builder-config-object

Addon-docs: Fix `BuilderConfig` can be an object
This commit is contained in:
Michael Shilman 2022-01-24 22:45:28 +08:00 committed by GitHub
commit 9f1bf78f55
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,7 @@ import remarkExternalLinks from 'remark-external-links';
// @ts-ignore
import { createCompiler } from '@storybook/csf-tools/mdx';
import type { Options } from '@storybook/core-common';
import type { BuilderConfig, 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
@ -38,12 +38,15 @@ export async function webpack(
typeof createCompiler
>[0]
) {
const { builder = 'webpack4' } = await options.presets.apply<{ builder: any }>('core', {} as any);
const { builder = 'webpack4' } = await options.presets.apply<{
builder: BuilderConfig;
}>('core', {} as any);
const builderName = typeof builder === 'string' ? builder : builder.name;
const resolvedBabelLoader = require.resolve('babel-loader', {
paths: builder.match(/(webpack4|webpack5)/)
paths: builderName.match(/(webpack4|webpack5)/)
? [require.resolve(`@storybook/builder-${builder}`)]
: [builder],
: [builderName],
});
const { module = {} } = webpackConfig;