From 476af4304a6a6624d71b14d27183e5a7a9f59ef2 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 15:57:38 +0200 Subject: [PATCH] fix: single chunk is not common --- packages/webpack/src/config/client.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index 2aa3d095f348..7c39f79c5ef1 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -74,24 +74,29 @@ export default class WebpackClientConfig extends WebpackBaseConfig { if (!this.dev && cacheGroups.default && cacheGroups.default.name === undefined) { cacheGroups.default.name = (_module, chunks) => { - // Use compact name for concatinated modules - let compactName = chunks - .filter(c => c.name) + // Map chunks to names + const names = chunks .map(c => c.name) + .filter(Boolean) .sort() .map(name => name.replace(/[/\\]/g, '.').replace(/_/g, '').replace('pages.', '')) - .join('~') // Fixes https://github.com/nuxt/nuxt.js/issues/7665 // TODO: We need a reproduction for this case (test/fixtures/shared-chunk) - if (!compactName) { - compactName = 'default' + if (!names.length) { + return 'commons/default' + } + + // Single chunk is not common + if (names.length === 1) { + return names[0] } + // Use compact name for concatinated modules + let compactName = names.join('~') if (compactName.length > 32) { compactName = hash(compactName) } - return 'commons/' + compactName } }