2019-03-14 16:04:08 +01:00
|
|
|
import { Compiler, Plugin } from 'webpack'
|
2019-03-15 05:08:22 +01:00
|
|
|
import { createHash } from 'crypto'
|
2019-03-14 16:04:08 +01:00
|
|
|
|
|
|
|
export class AllModulesIdentifiedPlugin implements Plugin {
|
|
|
|
apply(compiler: Compiler) {
|
|
|
|
compiler.hooks.compilation.tap(
|
|
|
|
'AllModulesIdentifiedPlugin',
|
|
|
|
compilation => {
|
|
|
|
compilation.hooks.beforeModuleIds.tap(
|
|
|
|
'AllModulesIdentifiedPlugin',
|
|
|
|
modules => {
|
2019-03-15 05:08:22 +01:00
|
|
|
;(modules as any[]).forEach(m => {
|
|
|
|
if (m.id != null || !m.identifier) {
|
2019-03-14 16:04:08 +01:00
|
|
|
return
|
|
|
|
}
|
2019-03-15 05:08:22 +01:00
|
|
|
|
2019-03-26 17:30:31 +01:00
|
|
|
const identifier = m.identifier()
|
2019-03-15 05:08:22 +01:00
|
|
|
|
|
|
|
// 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)
|
2019-03-14 16:04:08 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|