rsnext/packages/next/build/webpack/plugins/all-modules-identified-plugin.ts
Joe Haddad 0249b331c2
Use a shared module cache (#6791)
* [WIP] Use a shared module cache

* ID modules in development

* Revert "ID modules in development"

This reverts commit 0613d92fa2c8c7fa11a5ff5b7770d784af1cec63.

* Remove context replacement

* Only enable shared runtime in prod

* Sort settings

* Add shared runtime experimental setting

* only enable shared runtime in serverless
2019-03-26 12:30:31 -04:00

31 lines
892 B
TypeScript

import { Compiler, Plugin } from 'webpack'
import { createHash } from 'crypto'
export class AllModulesIdentifiedPlugin implements Plugin {
apply(compiler: Compiler) {
compiler.hooks.compilation.tap(
'AllModulesIdentifiedPlugin',
compilation => {
compilation.hooks.beforeModuleIds.tap(
'AllModulesIdentifiedPlugin',
modules => {
;(modules as any[]).forEach(m => {
if (m.id != null || !m.identifier) {
return
}
const identifier = m.identifier()
// 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)
})
}
)
}
)
}
}