-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9724 from webpack/bugfix/serve-regression
HMR plugin should only affect the root compilation
- Loading branch information
Showing
4 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default 1; | ||
--- | ||
export default 2; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import value, { assets } from "./report-child-assets-loader!./file"; | ||
|
||
it("should not emit hot updates from child compilers", done => { | ||
expect(value).toBe(1); | ||
expect(assets).toEqual(["test.js"]); | ||
module.hot.accept("./report-child-assets-loader!./file", () => { | ||
expect(value).toBe(2); | ||
expect(assets).toEqual(["test.js"]); | ||
done(); | ||
}); | ||
NEXT(require("../../update")(done)); | ||
}); |
32 changes: 32 additions & 0 deletions
32
test/hotCases/child-compiler/issue-9706/report-child-assets-loader.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const NodeTemplatePlugin = require("../../../../lib/node/NodeTemplatePlugin"); | ||
const FunctionModulePlugin = require("../../../../lib/FunctionModulePlugin"); | ||
const SingleEntryPlugin = require("../../../../lib/SingleEntryPlugin"); | ||
|
||
const compilerCache = new WeakMap(); | ||
|
||
module.exports = function(source) { | ||
let childCompiler = compilerCache.get(this._compiler); | ||
if (childCompiler === undefined) { | ||
childCompiler = this._compilation.createChildCompiler( | ||
"my-compiler|" + this.request, | ||
{ | ||
filename: "test.js" | ||
}, | ||
[ | ||
new NodeTemplatePlugin(), | ||
new FunctionModulePlugin(), | ||
new SingleEntryPlugin(this.context, this.resource) | ||
] | ||
); | ||
compilerCache.set(this._compiler, childCompiler); | ||
} | ||
const callback = this.async(); | ||
childCompiler.runAsChild((err, entries, compilation) => { | ||
if (err) return callback(err); | ||
|
||
const result = `export const assets = ${JSON.stringify( | ||
compilation.getAssets().map(a => a.name) | ||
)};\n${source}`; | ||
callback(null, result); | ||
}); | ||
}; |