rpflorence/react-nested-router — pull request #41 by sokra (2014-06-22 21:03:58+00:00)
Title: Use the bundle-loader to implement an AsyncReactComponent

webpack creates **one** chunk per `require.ensure`. To create a chunk per module you need one `require.ensure` per module. That's repeated work if you do this manually so the bundle-loader does it for you. So to keep most of the original code you could do it with:

``` diff
- require.ensure([], function() {
- this.routeCache[this.globalName] = require('./async-components/' + this.filePath);
+ require('bundle!./async-components/' + this.filePath)(function(component) {
+ this.routeCache[this.globalName] = component;
```

But this would only use components in a pre-defined path :( So a better practise is to not pass a path to a module, but to pass the bundle function. See PR. I also removed to global `routeCache` and replaced it with a static class var.