Skip to content

Commit

Permalink
Merge pull request #24843 from storybookjs/kasper/revert-swc-from-tes…
Browse files Browse the repository at this point in the history
…t-build

TestBuild: Revert defaulting to SWC in test build, but keep using esbuild for minification
  • Loading branch information
kasperpeulen authored Nov 14, 2023
2 parents 837936a + a668b98 commit 0e1f152
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
{
Expand Down Expand Up @@ -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<EsbuildOptions>({
parallel: true,
Expand Down
16 changes: 11 additions & 5 deletions code/lib/core-server/src/presets/common-override-preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
};
Expand All @@ -63,7 +69,7 @@ const createTestBuildFeatures = (value: boolean): Required<TestBuildFlags> => ({
disableDocgen: value,
disableSourcemaps: value,
disableTreeShaking: value,
fastCompilation: value,
esbuildMinify: value,
});

export const build = async (value: StorybookConfig['build'], options: Options) => {
Expand Down
4 changes: 2 additions & 2 deletions code/lib/types/src/modules/core-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 0e1f152

Please sign in to comment.