@@ -42,7 +42,6 @@ module.exports.pitch = function pitch(request) {
42
42
throw new Error ( "Only usable with webpack" ) ;
43
43
}
44
44
45
- this . cacheable ( false ) ;
46
45
const callback = this . async ( ) ;
47
46
const options = loaderUtils . getOptions ( this ) || { } ;
48
47
const compilerOptions = this . _compiler . options || { } ;
@@ -89,22 +88,38 @@ module.exports.pitch = function pitch(request) {
89
88
}
90
89
91
90
new SingleEntryPlugin ( this . context , `!!${ request } ` , "main" ) . apply ( workerCompiler ) ;
92
-
93
- const subCache = `subcache ${ __dirname } ${ request } ` ;
94
91
const plugin = { name : "WorkerLoader" } ;
95
92
96
- workerCompiler . hooks . compilation . tap ( plugin , compilation => {
97
- if ( compilation . cache ) {
98
- compilation . cache = compilation . cache [ subCache ] || { } ;
99
- }
93
+ workerCompiler . hooks . thisCompilation . tap ( plugin , compilation => {
94
+ /**
95
+ * A dirty hack to disable HMR plugin in childCompilation:
96
+ * https://github.com/webpack/webpack/blob/4056506488c1e071dfc9a0127daa61bf531170bf/lib/HotModuleReplacementPlugin.js#L154
97
+ *
98
+ * Once we update to webpack@4.40.3 and above this can be removed:
99
+ * https://github.com/webpack/webpack/commit/1c4138d6ac04b7b47daa5ec4475c0ae1b4f596a2
100
+ */
101
+ compilation . hotUpdateChunkTemplate = null ;
100
102
} ) ;
101
103
102
- workerCompiler . runAsChild ( ( err , entries ) => {
104
+ workerCompiler . runAsChild ( ( err , entries , childCompilation ) => {
103
105
if ( err ) {
104
106
return callback ( err ) ;
105
107
}
106
108
107
109
if ( entries [ 0 ] ) {
110
+ const fileDeps = Array . from ( childCompilation . fileDependencies ) ;
111
+ this . clearDependencies ( ) ;
112
+ fileDeps . map ( fileName => {
113
+ this . addDependency ( fileName ) ;
114
+ } ) ;
115
+ /**
116
+ * Clears the hash of the child compilation as it affects the hash of the parent compilation:
117
+ * https://github.com/webpack/webpack/blob/4056506488c1e071dfc9a0127daa61bf531170bf/lib/Compilation.js#L2281
118
+ *
119
+ * If we don't clear the hash an emit of runtime.js and an empty [somehash].hot-update.json will happen on save without changes.
120
+ * This will restart the NS application.
121
+ */
122
+ childCompilation . hash = "" ;
108
123
const workerFile = entries [ 0 ] . files [ 0 ] ;
109
124
this . _compilation . workerChunks . push ( workerFile ) ;
110
125
const workerFactory = getWorker ( workerFile ) ;
0 commit comments