-
-
Notifications
You must be signed in to change notification settings - Fork 9.2k
Closed
Labels
Description
Using require.ensure like so seems to work fine, and d3 gets split into a separate bundle file:
Router.prototype.someMethod = function() {};
Router.prototype.foo = function() {
require.ensure([], function() {
require("d3");
return this.someMethod();
});
};However, that call to this.someMethod() will fail, so I changed it to return a closure (switched -> to => in coffeescript):
Router.prototype.foo = function() {
require.ensure([], (function(_this) {
return function() {
require("d3");
return _this.someMethod();
};
})(this));
};This change seems to break the code splitting, producing a single bundle.js file.
I've worked around the issue for now by using Function.prototype.bind() instead of the closure, but the current behavior was very surprising and took me a while to track down, so it seems worthwhile to fix so others don't run into it as well.