Skip to content

Conversation

sokra
Copy link
Contributor

@sokra sokra commented Jun 22, 2014

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:

-    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.

to implement an AsyncReactComponent
ryanflorence added a commit that referenced this pull request Jun 23, 2014
Use the bundle-loader to implement an AsyncReactComponent
@ryanflorence ryanflorence merged commit 62be6b3 into remix-run:master Jun 23, 2014
@ryanflorence
Copy link
Member

awesome, thank you!

@lock lock bot locked as resolved and limited conversation to collaborators Jan 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants