mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
b1c4f3aec4
- Implements Lerna - Moves all source code into `packages/next` - Keeps integration tests in the root directory
33 lines
1.3 KiB
JavaScript
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
|
|
}
|
|
})
|
|
})
|
|
}
|
|
}
|