fix: revert named-chunks nameResolver algorithm (#2324)

* Revert "fix: avoid hash collisions (#1959)"

This reverts commit 4b5a63441b.

* Revert "refactor: improve chunk name aesthetics"

This reverts commit 625d541715.
This commit is contained in:
Haoqun Jiang
2018-09-04 16:51:48 +08:00
committed by GitHub
parent f9652a1d4f
commit 3933187f73

View File

@@ -119,25 +119,15 @@ module.exports = (api, options) => {
})
// keep chunk ids stable so async chunks have consistent hash (#1916)
const seen = new Set()
const nameLength = 4
webpackConfig
.plugin('named-chunks')
.use(require('webpack/lib/NamedChunksPlugin'), [chunk => {
if (chunk.name) {
return chunk.name
}
const modules = Array.from(chunk.modulesIterable)
if (modules.length > 1) {
const hash = require('hash-sum')
const joinedHash = hash(modules.map(m => m.id).join('_'))
let len = nameLength
while (seen.has(joinedHash.substr(0, len))) len++
seen.add(joinedHash.substr(0, len))
return `chunk-${joinedHash.substr(0, len)}`
} else {
return modules[0].id
}
return `chunk-` + Array.from(chunk.modulesIterable, m => {
return m.id
}).join('_')
}])
}