diff --git a/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts b/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts index 10704bc25d93..13b02df7264f 100644 --- a/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts +++ b/code/builders/builder-webpack5/src/preview/iframe-webpack.config.ts @@ -323,7 +323,7 @@ export default async ( fullySpecified: false, }, }, - builderOptions.useSWC || options.build?.test?.fastCompilation + builderOptions.useSWC ? await createSWCLoader(Object.keys(virtualModuleMapping), options) : createBabelLoader(babelOptions, typescriptOptions, Object.keys(virtualModuleMapping)), { @@ -362,7 +362,7 @@ export default async ( ? { minimize: true, // eslint-disable-next-line no-nested-ternary - minimizer: options.build?.test?.fastCompilation + minimizer: options.build?.test?.esbuildMinify ? [ new TerserWebpackPlugin({ parallel: true, diff --git a/code/lib/core-server/src/presets/common-override-preset.ts b/code/lib/core-server/src/presets/common-override-preset.ts index bffb3f3f0d26..5696701a88cd 100644 --- a/code/lib/core-server/src/presets/common-override-preset.ts +++ b/code/lib/core-server/src/presets/common-override-preset.ts @@ -19,7 +19,7 @@ export const framework: PresetProperty<'framework', StorybookConfig> = async (co export const stories: PresetProperty<'stories', StorybookConfig> = async (entries, options) => { if (options?.build?.test?.disableMDXEntries) { - const out = ( + return ( await Promise.all( normalizeStories(entries, { configDir: options.configDir, @@ -34,9 +34,15 @@ export const stories: PresetProperty<'stories', StorybookConfig> = async (entrie }); }) ) - ).reduce((carry, s) => carry.concat(s), []); - - return out.filter((s) => !s.endsWith('.mdx')); + ).flatMap((expanded, i) => { + const filteredEntries = expanded.filter((s) => !s.endsWith('.mdx')); + // only return the filtered entries when there is something to filter + // as webpack is faster with unexpanded globs + if (filteredEntries.length < expanded.length) { + return filteredEntries; + } + return entries[i]; + }); } return entries; }; @@ -63,7 +69,7 @@ const createTestBuildFeatures = (value: boolean): Required => ({ disableDocgen: value, disableSourcemaps: value, disableTreeShaking: value, - fastCompilation: value, + esbuildMinify: value, }); export const build = async (value: StorybookConfig['build'], options: Options) => { diff --git a/code/lib/types/src/modules/core-common.ts b/code/lib/types/src/modules/core-common.ts index 584618e337b3..f5043c362d7c 100644 --- a/code/lib/types/src/modules/core-common.ts +++ b/code/lib/types/src/modules/core-common.ts @@ -292,9 +292,9 @@ export interface TestBuildFlags { */ disableTreeShaking?: boolean; /** - * Compile/Optimize with SWC/ESbuild. + * Minify with ESBuild when using webpack. */ - fastCompilation?: boolean; + esbuildMinify?: boolean; } export interface TestBuildConfig {