mirror of https://github.com/webpack/webpack.git
Merge pull request #10256 from webpack/bugfix/chunk-id-hmr
use correct string or number form of chunk id in HMR
This commit is contained in:
commit
fee4d37968
|
|
@ -308,12 +308,12 @@ class HotModuleReplacementPlugin {
|
|||
};
|
||||
const allRemovedModules = new Set();
|
||||
for (const key of Object.keys(records.chunkHashs)) {
|
||||
const chunkId = key;
|
||||
const currentChunk = find(
|
||||
compilation.chunks,
|
||||
chunk => `${chunk.id}` === key
|
||||
);
|
||||
if (currentChunk) {
|
||||
const chunkId = currentChunk.id;
|
||||
const newModules = chunkGraph
|
||||
.getChunkModules(currentChunk)
|
||||
.filter(module => updatedModules.has(module));
|
||||
|
|
@ -372,6 +372,7 @@ class HotModuleReplacementPlugin {
|
|||
hotUpdateMainContent.c.push(chunkId);
|
||||
}
|
||||
} else {
|
||||
const chunkId = `${+key}` === key ? +key : key;
|
||||
hotUpdateMainContent.r.push(chunkId);
|
||||
for (const id of records.chunkModuleIds[chunkId])
|
||||
allRemovedModules.add(id);
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
export { value } from "./file";
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
import { value as v } from "./file";
|
||||
|
||||
export const value = v + 0.5;
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export var value = 1;
|
||||
---
|
||||
export var value = 1.5;
|
||||
---
|
||||
export var value = 3;
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
import m from "./module";
|
||||
|
||||
it("should add and remove chunks", done => {
|
||||
return m()
|
||||
.then(chunk => {
|
||||
expect(chunk.value).toBe(1);
|
||||
let update = 0;
|
||||
module.hot.accept("./module", () => {
|
||||
m()
|
||||
.then(chunk => {
|
||||
switch (update) {
|
||||
case 0:
|
||||
expect(chunk.value).toBe(2);
|
||||
break;
|
||||
case 1:
|
||||
expect(chunk.value).toBe(3);
|
||||
done();
|
||||
return;
|
||||
}
|
||||
update++;
|
||||
NEXT(require("../../update")(done));
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
NEXT(require("../../update")(done));
|
||||
})
|
||||
.catch(done);
|
||||
});
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
export default () => import(/* webpackChunkName: "1e1" */ "./chunk");
|
||||
---
|
||||
export default () => import(/* webpackChunkName: "10" */ "./chunk2");
|
||||
---
|
||||
export default () => import(/* webpackChunkName: "1e1" */ "./chunk");
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
export var value = 1;
|
||||
---
|
||||
export var value = 2;
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
import { value } from "./file";
|
||||
|
||||
it("should auto-import an ES6 imported value on accept", function(done) {
|
||||
expect(value).toBe(1);
|
||||
module.hot.accept("./file", function() {
|
||||
expect(value).toBe(2);
|
||||
outside();
|
||||
done();
|
||||
});
|
||||
NEXT(require("../../update")(done));
|
||||
});
|
||||
|
||||
function outside() {
|
||||
expect(value).toBe(2);
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
mode: "production",
|
||||
optimization: {
|
||||
minimize: false
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue