-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Code splitting on Gatsby? #3763
Comments
Gatsby uses webpack v1 currently (which will be updated in gatsby v2) and your code is valid in webpack v2+. Try this:
|
Oh! Thank you very much! |
@pieh I have tried but I got SEO is not defined.
|
I might started with wrong approach - why do you want to split this code? Peace of code i presented is for lazy loading modules, but when i reread your example it doesn't seem like SEO component should be lazy loaded as then this won't be used in generated static htmls. If SEO component is common in many of your templates (i think number is above 3 ) then gatsby will automatically place it in common chunk shared by all pages ( you can read some consideration about that decission in comment here - https://github.com/gatsbyjs/gatsby/blob/master/packages/gatsby/src/utils/webpack.config.js#L258 ) |
I want to load polyfills conditionally this way (no sense in loading a |
@tremby Gatsby v2 will do this automatically for you, if you want to do this in v1 you'll need to work out how to do it manually. |
v2 is almost out! Native support for |
Is this the same way you would do it for React 16.6 I tried a simple example last night and was getting Webpack errors https://github.com/spences10/scottspence.me/blob/dev/use-react-lazy/src/pages/index.js |
I am also facing same issue when trying with |
@spences10 @vamsi1317 are you both seeing this error? Specifically, my local build works just fine, but in the SSR phase, I receive the following error
See my reproduction here |
Hi @DSchau yes, that is the error, here's the output from Netlify: https://app.netlify.com/sites/scottspence/deploys/5c0769a00097d44d7e7b0227 |
Is there a fix for this? getting the same error. |
Maybe re-open this for visibility |
I'm not sure but it seems that:
( https://reactjs.org/docs/code-splitting.html#reactlazy ) might be the root cause of this? I'm not sure if we can workaround this |
Yes, I ended up replacing |
reactjs.org/docs/code-splitting.html#reactlazy ) Thanks so much for opening this issue! As stated, this is slightly tangential to Gatsby, and it seems like we’ve provided enough information to make an informed decision. If this is not the case, or if we can help further--please don’t hesitate to reach out or comment on this issue, and we’d love to take another look. Thanks for using Gatsby 💪 |
Quick update. Suspense is the problem. Then, if you perform |
FWIW, #3763 (comment) works but {typeof window !== 'undefined' && (
<React.Suspense fallback={<Loading />}>
<LazyThing />
</React.Suspense>
)} |
I really curious that Can I have a code-splitting by using this line of code ?
I got an error in the following lines when I run
gatsby develop
The text was updated successfully, but these errors were encountered: