Skip to content

Commit

Permalink
Webpack5: Load babel-options only when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinpalkovic committed Nov 28, 2023
1 parent 4933c17 commit 0adaf29
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 8 deletions.
2 changes: 0 additions & 2 deletions code/builders/builder-webpack5/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,13 @@ export const executor = {
export const getConfig: WebpackBuilder['getConfig'] = async (options) => {
const { presets } = options;
const typescriptOptions = await presets.apply('typescript', {}, options);
const babelOptions = await presets.apply('babel', {}, { ...options, typescriptOptions });
const frameworkOptions = await presets.apply<any>('frameworkOptions');

return presets.apply(
'webpack',
{},
{
...options,
babelOptions,
typescriptOptions,
frameworkOptions,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const storybookPaths: Record<string, string> = {
};

export default async (
options: Options & Record<string, any> & { typescriptOptions: TypescriptOptions }
options: Options & { typescriptOptions: TypescriptOptions }
): Promise<Configuration> => {
const {
outputDir = join('.', 'public'),
Expand All @@ -66,7 +66,6 @@ export default async (
configType,
presets,
previewUrl,
babelOptions,
typescriptOptions,
features,
} = options;
Expand Down Expand Up @@ -240,7 +239,7 @@ export default async (
},
builderOptions.useSWC
? await createSWCLoader(Object.keys(virtualModuleMapping), options)
: createBabelLoader(babelOptions, typescriptOptions, Object.keys(virtualModuleMapping)),
: await createBabelLoader(options, typescriptOptions, Object.keys(virtualModuleMapping)),
{
test: /\.md$/,
type: 'asset/source',
Expand Down
7 changes: 4 additions & 3 deletions code/builders/builder-webpack5/src/preview/loaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@ import { logger } from '@storybook/node-logger';
import type { Options } from '@storybook/types';
import type { TypescriptOptions } from '../types';

export const createBabelLoader = (
options: any,
export const createBabelLoader = async (
options: Options & { typescriptOptions: TypescriptOptions },
typescriptOptions: TypescriptOptions,
excludes: string[] = []
) => {
logger.info(dedent`Using Babel compiler`);
const babelOptions = await options.presets.apply('babel', {}, options);
return {
test: typescriptOptions.skipBabel ? /\.(mjs|jsx?)$/ : /\.(mjs|tsx?|jsx?)$/,
use: [
{
loader: require.resolve('babel-loader'),
options,
options: babelOptions,
},
],
include: [getProjectRoot()],
Expand Down

0 comments on commit 0adaf29

Please sign in to comment.