From b75dc47ea7fc89a7db4c96b08ddb57353c47304b Mon Sep 17 00:00:00 2001 From: Ward Peeters Date: Tue, 7 Apr 2020 10:43:48 +0200 Subject: [PATCH] fix(gatsby): improve async commons chunking --- packages/gatsby/src/utils/webpack.config.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/src/utils/webpack.config.js b/packages/gatsby/src/utils/webpack.config.js index a37c90f315bfc..993055a638cda 100644 --- a/packages/gatsby/src/utils/webpack.config.js +++ b/packages/gatsby/src/utils/webpack.config.js @@ -530,10 +530,13 @@ module.exports = async ( reuseExistingChunk: true, }, commons: { + // only bundle non-async modules + chunks: `initial`, name: `commons`, - // if a chunk is used on all components we put it in commons - minChunks: componentsCount, + // if a chunk is used on all components we put it in commons (we need at least 2 components) + minChunks: Math.max(componentsCount, 2), priority: 20, + reuseExistingChunk: true, }, // If a chunk is used in at least 2 components we create a separate chunk shared: {