Skip to content

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

Merged
merged 5 commits into from
Aug 26, 2018
Merged

Update code-splitting.md #2153

merged 5 commits into from
Aug 26, 2018

Conversation

tiendo1011
Copy link
Contributor

@tiendo1011 tiendo1011 commented May 15, 2018

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.

Fixes #2154

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.
@EugeneHlushko
Copy link
Member

@montogeek @jeremenichelli this is exactly why we had issue with page's module content, if you remember we did module.default check

Copy link
Member

@EugeneHlushko EugeneHlushko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great spot on 👍

@montogeek
Copy link
Member

montogeek commented May 16, 2018

This was done in another PR.
Edit: https://github.com/webpack/webpack.js.org/pull/1904/files

@montogeek
Copy link
Member

This PR have same changes but also some others, we can merge both.

@EugeneHlushko
Copy link
Member

Yeap but this one is complete thanks to the explanation paragraph and also uses modern assignment approach e.g. ({ default: _ }) => ... i would suggest merging both (the older first) or only this one as it is in a complete state for both examples on line 246 and 295

@montogeek
Copy link
Member

montogeek commented May 16, 2018

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 ¯\(ツ)

@EugeneHlushko
Copy link
Member

mm in that case we might ask @tiendo1011 to update this with es5 ?

@tiendo1011
Copy link
Contributor Author

tiendo1011 commented May 17, 2018

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: _ }) => {
Copy link

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');
Copy link

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(_ => { ...}

@montogeek
Copy link
Member

@tiendo1011 Friendly ping

@montogeek
Copy link
Member

@asapach Please take a look again

@asapach
Copy link

asapach commented Aug 26, 2018

LGTM

@montogeek montogeek merged commit 8e1e8b1 into webpack:master Aug 26, 2018
@montogeek
Copy link
Member

Thanks!

@tiendo1011 tiendo1011 deleted the patch-1 branch August 27, 2018 01:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Need update docs: Dynamic import doesn't work as shown in the docs
5 participants