Skip to content
This repository has been archived by the owner on Sep 9, 2021. It is now read-only.

Commit

Permalink
fix(index): add webpack >= v4.0.0 support (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-ciniawsky authored Feb 25, 2018
1 parent 8905f8d commit d1a7a94
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export function pitch(request) {
const cb = this.async();

const filename = loaderUtils.interpolateName(this, options.name || '[hash].worker.js', {
context: options.context || this.options.context,
context: options.context || this.rootContext || this.options.context,
regExp: options.regExp,
});

Expand All @@ -62,13 +62,23 @@ export function pitch(request) {

const subCache = `subcache ${__dirname} ${request}`;

worker.compiler.plugin('compilation', (compilation) => {
worker.compilation = (compilation) => {
if (compilation.cache) {
if (!compilation.cache[subCache]) compilation.cache[subCache] = {};
if (!compilation.cache[subCache]) {
compilation.cache[subCache] = {};
}

compilation.cache = compilation.cache[subCache];
}
});
};

if (worker.compiler.hooks) {
const plugin = { name: 'WorkerLoader' };

worker.compiler.hooks.compilation.tap(plugin, worker.compilation);
} else {
worker.compiler.plugin('compilation', worker.compilation);
}

worker.compiler.runAsChild((err, entries, compilation) => {
if (err) return cb(err);
Expand Down

0 comments on commit d1a7a94

Please sign in to comment.