Skip to content

Commit

Permalink
fix: html-webpack-plugin child compiler chunk id (#56)
Browse files Browse the repository at this point in the history
* fix: html-webpack-plugin child compiler. fixes #55

* chore: remove markdown-toc

the author of markdown-toc also owns remarkable, and has a policy
of not updating for reported security issues.
see: jonschlinkert/remarkable#312
  • Loading branch information
shellscape committed Dec 14, 2018
1 parent b81d8bc commit 2f0468d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 267 deletions.
15 changes: 14 additions & 1 deletion lib/hmr-plugin.js
Expand Up @@ -41,10 +41,16 @@ const hookPlugin = (compiler) => {

compiler.hooks.compilation.tap('wps', (compilation) => {
const { mainTemplate } = compilation;
const { assetPath, hotBootstrap } = mainTemplate.hooks;
const { assetPath, hashForChunk, hotBootstrap } = mainTemplate.hooks;
const { additionalChunkAssets } = compilation.hooks;
let currentChunk;

// fixes #55. html-webpack-plugin uses a child compiler which alters the order of chunk
// processing, calling assetPath before hotBootstrap.
hashForChunk.tap('wps', (hash, chunk) => {
currentChunk = chunk;
});

intercept(hotBootstrap, 'JsonpMainTemplatePlugin', (hook, ogFn) => {
hook.fn = (source, chunk, hash) => {
currentChunk = chunk;
Expand All @@ -57,6 +63,12 @@ const hookPlugin = (compiler) => {
const mainTest = `"${mainPlaceholder}"`;

hook.fn = (path, data) => {
// html-webpack-plugin doesn't call the same hooks that normal assets do. currentChunk will
// always be undefined for its files.
if (!currentChunk) {
return ogFn(path, data);
}

const { hotUpdateChunkFilename, hotUpdateMainFilename } = compiler.options.output;

if (path === chunkTest) {
Expand All @@ -72,6 +84,7 @@ const hookPlugin = (compiler) => {
oldHotUpdateMainFilename: hotUpdateMainFilename
});
}

return ogFn(path, data);
};
});
Expand Down

0 comments on commit 2f0468d

Please sign in to comment.