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

Commit d1a7a94

Browse files
fix(index): add webpack >= v4.0.0 support (#128)
1 parent 8905f8d commit d1a7a94

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/index.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export function pitch(request) {
3737
const cb = this.async();
3838

3939
const filename = loaderUtils.interpolateName(this, options.name || '[hash].worker.js', {
40-
context: options.context || this.options.context,
40+
context: options.context || this.rootContext || this.options.context,
4141
regExp: options.regExp,
4242
});
4343

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

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

65-
worker.compiler.plugin('compilation', (compilation) => {
65+
worker.compilation = (compilation) => {
6666
if (compilation.cache) {
67-
if (!compilation.cache[subCache]) compilation.cache[subCache] = {};
67+
if (!compilation.cache[subCache]) {
68+
compilation.cache[subCache] = {};
69+
}
6870

6971
compilation.cache = compilation.cache[subCache];
7072
}
71-
});
73+
};
74+
75+
if (worker.compiler.hooks) {
76+
const plugin = { name: 'WorkerLoader' };
77+
78+
worker.compiler.hooks.compilation.tap(plugin, worker.compilation);
79+
} else {
80+
worker.compiler.plugin('compilation', worker.compilation);
81+
}
7282

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

0 commit comments

Comments
 (0)