Skip to content

Commit 50c0220

Browse files
authored
Merge pull request webpack#3386 from chuckdumont/webpack-1
Fix lost context when invoking require()
2 parents 5a56be9 + 938dc66 commit 50c0220

File tree

5 files changed

+24
-2
lines changed

5 files changed

+24
-2
lines changed

lib/dependencies/DepBlockHelpers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ DepBlockHelpers.getLoadDepBlockWrapper = function(depBlock, outputOptions, reque
2525
"if(--__WEBPACK_REMAINING_CHUNKS__ < 1) (",
2626

2727
"(__webpack_require__));" +
28-
"};" +
28+
"}.bind(this);" +
2929
chunks.map(function(chunk) {
3030
return "__webpack_require__.e(" + chunk.id + ", __WEBPACK_CALLBACK__);";
3131
}).join("") +
32-
"}())"
32+
"}).call(this)"
3333
];
3434
}
3535
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "b";
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
it("should maintain require context", function(done) {
2+
var context = {foo: "bar"};
3+
(function(){
4+
require(["./a", "./b"], function(a, b) {
5+
this.foo.should.eql("bar");
6+
done();
7+
}.bind(this));
8+
}).call(context);
9+
// Call require again so that CommonsChunkPlugin will create separate chunks for a and b
10+
require(["./a"], function(a) {});
11+
});
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
var webpack = require("../../../../");
2+
3+
module.exports = {
4+
plugins: [
5+
new webpack.optimize.CommonsChunkPlugin({
6+
async: true
7+
})
8+
]
9+
};

0 commit comments

Comments
 (0)