From e4b65985c64df2b48e75ac036429be6e23f8ab1c Mon Sep 17 00:00:00 2001 From: Simon Tretter Date: Fri, 3 Jul 2020 18:20:28 +0200 Subject: [PATCH 1/8] fix(webpack): fallback for empty chunk names fixes #7665 --- packages/webpack/src/config/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index 449c54bf5aee..d38b33210f51 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -84,7 +84,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig { .map(c => c.name) .sort() .map(name => name.replace(/[/\\]/g, '.').replace(/_/g, '').replace('pages.', '')) - .join('~') + .join('~') || 'default' if (compactName.length > 32) { compactName = hash(compactName) From fe3adb4290ad567f2595ab083d61f44b75cf7bf5 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 14:01:51 +0200 Subject: [PATCH 2/8] test: add dynamic import to shared-chunk fixture --- test/fixtures/shared-chunk/components/lazy.vue | 5 +++++ test/fixtures/shared-chunk/pages/index.vue | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/fixtures/shared-chunk/components/lazy.vue diff --git a/test/fixtures/shared-chunk/components/lazy.vue b/test/fixtures/shared-chunk/components/lazy.vue new file mode 100644 index 000000000000..fb0613e2e778 --- /dev/null +++ b/test/fixtures/shared-chunk/components/lazy.vue @@ -0,0 +1,5 @@ + diff --git a/test/fixtures/shared-chunk/pages/index.vue b/test/fixtures/shared-chunk/pages/index.vue index d380811d6062..79ee94f132df 100644 --- a/test/fixtures/shared-chunk/pages/index.vue +++ b/test/fixtures/shared-chunk/pages/index.vue @@ -1,5 +1,14 @@ + + From 677c81b9c7e766c47090659ab71a90eb7eb32e51 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 14:04:00 +0200 Subject: [PATCH 3/8] test: enable moderrn for shared-chunk fixture --- test/fixtures/shared-chunk/nuxt.config.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/fixtures/shared-chunk/nuxt.config.js b/test/fixtures/shared-chunk/nuxt.config.js index 140850c61363..3c6e6c4a919a 100644 --- a/test/fixtures/shared-chunk/nuxt.config.js +++ b/test/fixtures/shared-chunk/nuxt.config.js @@ -1,3 +1,4 @@ export default { - components: true + components: true, + modern: true } From dd99d1f4672568cec2baa6f33a06bce0b7c6fb9a Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 14:05:54 +0200 Subject: [PATCH 4/8] chore: add todo for adding reproduction --- packages/webpack/src/config/client.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index d38b33210f51..bf9d90a7269b 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -84,7 +84,13 @@ export default class WebpackClientConfig extends WebpackBaseConfig { .map(c => c.name) .sort() .map(name => name.replace(/[/\\]/g, '.').replace(/_/g, '').replace('pages.', '')) - .join('~') || 'default' + .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 (compactName.length > 32) { compactName = hash(compactName) From faf3dedade2d9fe35d6ffcb535e8be1aebc207af Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 14:18:04 +0200 Subject: [PATCH 5/8] refactor: always fallback to default if chunk have no name --- packages/webpack/src/config/client.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index bf9d90a7269b..2aa3d095f348 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -74,10 +74,6 @@ export default class WebpackClientConfig extends WebpackBaseConfig { if (!this.dev && cacheGroups.default && cacheGroups.default.name === undefined) { cacheGroups.default.name = (_module, chunks) => { - // Use default name for single chunks - if (chunks.length === 1) { - return chunks[0].name || '' - } // Use compact name for concatinated modules let compactName = chunks .filter(c => c.name) From 476af4304a6a6624d71b14d27183e5a7a9f59ef2 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 15:57:38 +0200 Subject: [PATCH 6/8] 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 } } From efc1c2b57e27279d7a035a413e6f2123f5e78d22 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 15:58:51 +0200 Subject: [PATCH 7/8] fix: do filter after normalizing --- packages/webpack/src/config/client.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index 7c39f79c5ef1..6f832455ea9b 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -77,9 +77,13 @@ export default class WebpackClientConfig extends WebpackBaseConfig { // Map chunks to names const names = chunks .map(c => c.name) + .map(name => name + .replace(/[/\\]/g, '.') + .replace(/_/g, '') + .replace('pages.', '') + ) .filter(Boolean) .sort() - .map(name => name.replace(/[/\\]/g, '.').replace(/_/g, '').replace('pages.', '')) // Fixes https://github.com/nuxt/nuxt.js/issues/7665 // TODO: We need a reproduction for this case (test/fixtures/shared-chunk) From ac60eb3c5ebf4702036a276161c64ca09f2a6606 Mon Sep 17 00:00:00 2001 From: pooya parsa Date: Sat, 4 Jul 2020 15:59:16 +0200 Subject: [PATCH 8/8] fix: ensure name is string just in case --- packages/webpack/src/config/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/webpack/src/config/client.js b/packages/webpack/src/config/client.js index 6f832455ea9b..58745992d70e 100644 --- a/packages/webpack/src/config/client.js +++ b/packages/webpack/src/config/client.js @@ -76,7 +76,7 @@ export default class WebpackClientConfig extends WebpackBaseConfig { cacheGroups.default.name = (_module, chunks) => { // Map chunks to names const names = chunks - .map(c => c.name) + .map(c => c.name || '') .map(name => name .replace(/[/\\]/g, '.') .replace(/_/g, '')