未验证 提交 d7ab018f 编写于 作者: J Joe Haddad 提交者: GitHub

Hash module IDs to save on bundle size (#6660)

上级 8dd71851
import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'
export class AllModulesIdentifiedPlugin implements Plugin {
apply(compiler: Compiler) {
......@@ -8,11 +9,23 @@ export class AllModulesIdentifiedPlugin implements Plugin {
compilation.hooks.beforeModuleIds.tap(
'AllModulesIdentifiedPlugin',
modules => {
;(modules as any[]).forEach(module => {
if (module.id != null || !module.identifier) {
;(modules as any[]).forEach(m => {
if (m.id != null || !m.identifier) {
return
}
module.id = module.identifier()
const identifier = m
.identifier()
// Ensure the context isn't included in the hash (this normally
// isn't present)
.replace(m.context, '')
// This hashing algorithm is consistent with how the rest of
// webpack does it (n.b. HashedModuleIdsPlugin)
m.id = createHash('md4')
.update(identifier)
.digest('hex')
.substr(0, 4)
})
}
)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册