Unverified Commit d7ab018f authored by Joe Haddad's avatar Joe Haddad Committed by GitHub

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

parent 8dd71851
import { Compiler, Plugin } from 'webpack' import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'
export class AllModulesIdentifiedPlugin implements Plugin { export class AllModulesIdentifiedPlugin implements Plugin {
apply(compiler: Compiler) { apply(compiler: Compiler) {
...@@ -8,11 +9,23 @@ export class AllModulesIdentifiedPlugin implements Plugin { ...@@ -8,11 +9,23 @@ export class AllModulesIdentifiedPlugin implements Plugin {
compilation.hooks.beforeModuleIds.tap( compilation.hooks.beforeModuleIds.tap(
'AllModulesIdentifiedPlugin', 'AllModulesIdentifiedPlugin',
modules => { modules => {
;(modules as any[]).forEach(module => { ;(modules as any[]).forEach(m => {
if (module.id != null || !module.identifier) { if (m.id != null || !m.identifier) {
return 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% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment