Skip to content

Commit 50233f8

Browse files
committed
Do not generated bad code when named chunks are merged or empty
fixed webpack/webpack-dev-server#30
1 parent 80f3c48 commit 50233f8

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

lib/dependencies/RequireEnsureDependency.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ RequireEnsureDependency.Template = function RequireEnsureDependencyTemplate() {}
1818

1919
RequireEnsureDependency.Template.prototype.apply = function(dep, source, outputOptions, requestShortener) {
2020
var depBlock = dep.block;
21-
if(depBlock.chunkNameRange) {
22-
var comment = "";
23-
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(depBlock.chunkName) + " */ ";
24-
source.replace(depBlock.chunkNameRange[0], depBlock.chunkNameRange[1]-1, comment + "0");
25-
}
2621
if(depBlock.chunk && !depBlock.chunk.entry && typeof depBlock.chunk.id === "number") {
22+
if(depBlock.chunkNameRange) {
23+
var comment = "";
24+
if(outputOptions.pathinfo) comment = "/*! " + requestShortener.shorten(depBlock.chunkName) + " */ ";
25+
source.replace(depBlock.chunkNameRange[0], depBlock.chunkNameRange[1]-1, comment + "0");
26+
}
2727
source.replace(depBlock.expr.callee.range[0], depBlock.expr.callee.range[1]-1, "__webpack_require__.e/*nsure*/");
2828
source.replace(depBlock.expr.arguments[0].range[0], depBlock.expr.arguments[0].range[1]-1, (depBlock.chunk.id) + "" + asComment(depBlock.chunkReason));
2929
} else {

test/cases/chunks/named-chunks/index.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,15 @@ it("should handle named chunks", function(done) {
1616
}, "named-chunk");
1717
}
1818
});
19+
20+
it("should handle empty named chunks", function(done) {
21+
var sync = false;
22+
require.ensure([], function(require) {
23+
sync.should.be.ok;
24+
}, "empty-named-chunk");
25+
require.ensure([], function(require) {
26+
sync.should.be.ok;
27+
done();
28+
}, "empty-named-chunk");
29+
sync = false;
30+
});

0 commit comments

Comments
 (0)