Skip to content

Commit 625d541

Browse files
committed
refactor: improve chunk name aesthetics
1 parent 2a60169 commit 625d541

File tree

1 file changed

+12
-3
lines changed
  • packages/@vue/cli-service/lib/config

1 file changed

+12
-3
lines changed

packages/@vue/cli-service/lib/config/app.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,24 @@ module.exports = (api, options) => {
7474
})
7575

7676
// keep chunk ids stable so async chunks have consistent hash (#1916)
77+
const seen = new Set()
78+
const nameLength = 4
7779
webpackConfig
7880
.plugin('named-chunks')
7981
.use(require('webpack/lib/NamedChunksPlugin'), [chunk => {
8082
if (chunk.name) {
8183
return chunk.name
8284
}
83-
return `chunk-` + Array.from(chunk.modulesIterable, m => {
84-
return m.id
85-
}).join('_')
85+
const modules = Array.from(chunk.modulesIterable)
86+
if (modules.length > 1) {
87+
const hash = require('hash-sum')
88+
const joinedHash = hash(modules.map(m => m.id).join('_'))
89+
let len = nameLength
90+
while (seen.has(joinedHash.substr(0, len))) len++
91+
return `chunk-${joinedHash.substr(0, len)}`
92+
} else {
93+
return modules[0].id
94+
}
8695
}])
8796
}
8897

0 commit comments

Comments
 (0)