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

Webpack5: Fix lazy compilation/fscache builderOptions when base config is disabled #19387

Merged
merged 2 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 13
parallelism: 12
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -336,7 +336,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 13
parallelism: 12
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -352,7 +352,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 13
parallelism: 12
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -372,7 +372,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 13
parallelism: 12
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -388,7 +388,7 @@ jobs:
executor:
class: medium+
name: sb_node_14_browsers
parallelism: 13
parallelism: 12
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand All @@ -404,7 +404,7 @@ jobs:
executor:
class: medium+
name: sb_playwright
parallelism: 13
parallelism: 12
steps:
- git-shallow-clone/checkout_advanced:
clone_options: '--depth 1 --verbose'
Expand Down
14 changes: 1 addition & 13 deletions code/lib/builder-webpack5/src/preview/base-webpack.config.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -94,7 +84,5 @@ export async function createDefaultWebpackConfig(
...storybookBaseConfig.resolve?.fallback,
},
},
...cacheConfig,
experiments: { ...storybookBaseConfig.experiments, ...lazyCompilationConfig },
};
}
14 changes: 13 additions & 1 deletion code/lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -289,5 +299,7 @@ export default async (
performance: {
hints: isProd ? 'warning' : false,
},
...cacheConfig,
experiments: { ...lazyCompilationConfig },
};
};