move code for setting builderOptions unto webpack5 builder to the other webpack config partial

This commit is contained in:
Norbert de Langen 2022-10-07 09:50:32 +02:00
parent a2cdd73b48
commit d1c990cdc9
No known key found for this signature in database
GPG Key ID: FD0E78AF9A837762
2 changed files with 14 additions and 14 deletions

View File

@ -1,7 +1,6 @@
import { logger } from '@storybook/node-logger';
import type { Options, CoreConfig } from '@storybook/core-common';
import type { Options } from '@storybook/core-common';
import type { Configuration } from 'webpack';
import type { BuilderOptions } from '../types';
export async function createDefaultWebpackConfig(
storybookBaseConfig: Configuration,
@ -45,15 +44,6 @@ export async function createDefaultWebpackConfig(
const isProd = storybookBaseConfig.mode !== 'development';
const coreOptions = await options.presets.apply<CoreConfig>('core');
const builderOptions: BuilderOptions =
typeof coreOptions.builder === 'string'
? {}
: coreOptions.builder?.options || ({} as BuilderOptions);
const cacheConfig = builderOptions.fsCache ? { cache: { type: 'filesystem' as const } } : {};
const lazyCompilationConfig =
builderOptions.lazyCompilation && !isProd ? { lazyCompilation: { entries: false } } : {};
return {
...storybookBaseConfig,
module: {
@ -94,7 +84,5 @@ export async function createDefaultWebpackConfig(
...storybookBaseConfig.resolve?.fallback,
},
},
...cacheConfig,
experiments: { ...storybookBaseConfig.experiments, ...lazyCompilationConfig },
};
}

View File

@ -78,7 +78,9 @@ export default async (
const template = await presets.apply<string>('previewMainTemplate');
const coreOptions = await presets.apply<CoreConfig>('core');
const builderOptions: BuilderOptions =
typeof coreOptions.builder === 'string' ? {} : coreOptions.builder?.options || {};
typeof coreOptions.builder === 'string'
? {}
: coreOptions.builder?.options || ({} as BuilderOptions);
const docsOptions = await presets.apply<DocsOptions>('docs');
const previewAnnotations = [
@ -160,6 +162,14 @@ export default async (
const shouldCheckTs = typescriptOptions.check && !typescriptOptions.skipBabel;
const tsCheckOptions = typescriptOptions.checkOptions || {};
const cacheConfig = builderOptions.fsCache ? { cache: { type: 'filesystem' as const } } : {};
const lazyCompilationConfig =
builderOptions.lazyCompilation && !isProd
? {
lazyCompilation: { entries: false },
}
: {};
return {
name: 'preview',
mode: isProd ? 'production' : 'development',
@ -289,5 +299,7 @@ export default async (
performance: {
hints: isProd ? 'warning' : false,
},
...cacheConfig,
experiments: { ...lazyCompilationConfig },
};
};