-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Update code-splitting.md #2153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update code-splitting.md #2153
Conversation
Since webpack 4, when using `dynamic import` to resolve commonJS module, it no longer resolve directly to the value of `module.exports`, but create an artificial namespace object to wrap it instead.
@montogeek @jeremenichelli this is exactly why we had issue with page's module content, if you remember we did |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great spot on 👍
This was done in another PR. |
This PR have same changes but also some others, we can merge both. |
Yeap but this one is complete thanks to the explanation paragraph and also uses modern assignment approach e.g. |
Yeah, still not sure if we want to push ES6 on our code examples, need to check other examples style. I would say that it is safe these days, but still ¯\(ツ)/¯ |
mm in that case we might ask @tiendo1011 to update this with es5 ? |
I think using ES6 is the way to go, as we already use it in that example (with arrow function). Beside, our examples look a lot more clean with it. |
@@ -242,7 +243,7 @@ __src/index.js__ | |||
- | |||
- // Lodash, now imported by this script | |||
- element.innerHTML = _.join(['Hello', 'webpack'], ' '); | |||
+ return import(/* webpackChunkName: "lodash" */ 'lodash').then(_ => { | |||
+ return import(/* webpackChunkName: "lodash" */ 'lodash').then(({ default: _ }) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a similar line of code on line 286, which should also be updated.
@@ -281,7 +284,7 @@ __src/index.js__ | |||
- | |||
- }).catch(error => 'An error occurred while loading the component'); | |||
+ var element = document.createElement('div'); | |||
+ const _ = await import(/* webpackChunkName: "lodash" */ 'lodash'); | |||
+ const { default: _ } = await import(/* webpackChunkName: "lodash" */ 'lodash'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...and a couple of lines above - see .then(_ => { ...}
@tiendo1011 Friendly ping |
@asapach Please take a look again |
LGTM |
Thanks! |
Since webpack 4, when using
dynamic import
to resolve commonJS module, it no longer resolve directly to the value ofmodule.exports
, but create an artificial namespace object to wrap it instead.Fixes #2154