Skip to content

Commit

Permalink
fix: single chunk is not common
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Jul 4, 2020
1 parent faf3ded commit 476af43
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/webpack/src/config/client.js
Expand Up @@ -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
}
}
Expand Down

0 comments on commit 476af43

Please sign in to comment.