1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00
next.js/build/webpack/plugins/chunk-names-plugin.js
Tim Neutkens 75476a9136
[WIP] Webpack 4, react-error-overlay, react-loadable (#4639)
Webpack 4, react-error-overlay, react-loadable (major)
2018-07-24 11:24:40 +02:00

33 lines
1.3 KiB
JavaScript

// This plugin mirrors webpack 3 `filename` and `chunkfilename` behavior
// This fixes https://github.com/webpack/webpack/issues/6598
// This plugin is based on https://github.com/researchgate/webpack/commit/2f28947fa0c63ccbb18f39c0098bd791a2c37090
export default class ChunkNamesPlugin {
apply (compiler) {
compiler.hooks.compilation.tap('NextJsChunkNamesPlugin', (compilation) => {
compilation.chunkTemplate.hooks.renderManifest.intercept({
register (tapInfo) {
if (tapInfo.name === 'JavascriptModulesPlugin') {
const originalMethod = tapInfo.fn
tapInfo.fn = (result, options) => {
let filenameTemplate
const chunk = options.chunk
const outputOptions = options.outputOptions
if (chunk.filenameTemplate) {
filenameTemplate = chunk.filenameTemplate
} else if (chunk.hasEntryModule()) {
filenameTemplate = outputOptions.filename
} else {
filenameTemplate = outputOptions.chunkFilename
}
options.chunk.filenameTemplate = filenameTemplate
return originalMethod(result, options)
}
}
return tapInfo
}
})
})
}
}