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: Add lazy compilation #17501

Merged
merged 4 commits into from
Feb 17, 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
2 changes: 1 addition & 1 deletion lib/builder-webpack4/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
},
runtimeChunk: true,
sideEffects: true,
usedExports: true,
usedExports: isProd,
moduleIds: 'named',
minimizer: isProd
? [
Expand Down
12 changes: 7 additions & 5 deletions lib/builder-webpack5/src/preview/base-webpack.config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@storybook/node-logger';
import type { Options, CoreConfig, Webpack5BuilderConfig } from '@storybook/core-common';
import type { Configuration } from 'webpack';
import { Configuration } from 'webpack';

export async function createDefaultWebpackConfig(
storybookBaseConfig: Configuration,
Expand Down Expand Up @@ -45,11 +45,12 @@ export async function createDefaultWebpackConfig(
const isProd = storybookBaseConfig.mode !== 'development';

const coreOptions = await options.presets.apply<CoreConfig>('core');
const cacheConfig = (coreOptions.builder as Webpack5BuilderConfig).options?.fsCache
? {
cache: { type: 'filesystem' as 'filesystem' },
}
const builderOptions = (coreOptions.builder as Webpack5BuilderConfig).options;
const cacheConfig = builderOptions?.fsCache
? { cache: { type: 'filesystem' as 'filesystem' } }
: {};
const lazyCompilationConfig =
builderOptions?.lazyCompilation && !isProd ? { lazyCompilation: { entries: false } } : {};
return {
...storybookBaseConfig,
module: {
Expand Down Expand Up @@ -91,5 +92,6 @@ export async function createDefaultWebpackConfig(
},
},
...cacheConfig,
experiments: { ...storybookBaseConfig.experiments, ...lazyCompilationConfig },
};
}
2 changes: 1 addition & 1 deletion lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default async (options: Options & Record<string, any>): Promise<Configura
},
runtimeChunk: true,
sideEffects: true,
usedExports: true,
usedExports: isProd,
moduleIds: 'named',
minimizer: isProd
? [
Expand Down
1 change: 1 addition & 0 deletions lib/core-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface Webpack5BuilderConfig extends BuilderConfigObject {
name: 'webpack5';
options?: {
fsCache?: boolean;
lazyCompilation?: boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to document this somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a separate ticket to do this, do you want to hold the PR for it?

};
}

Expand Down