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 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 16 additions & 5 deletions addons/docs/src/frameworks/common/preset.ts
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,22 @@ 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]
) {
// @ts-ignore
const { builder = 'webpack4' } = await options.presets.apply('core', {});

const resolvedBabelLoader = require.resolve('babel-loader', {
paths: [require.resolve(`@storybook/builder-${builder}`)], // FIXME!!!
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if the builder is storybook-builder-vite? Also what about the FIXME?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixme can be removed, it's fixed.

I didn't think of the storybook-builder-vite.

});

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