-
-
Notifications
You must be signed in to change notification settings - Fork 638
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
Feature: Add Code Splitting #596
Conversation
How does The main.js bundle contains all the components inside
Do you know why is that happening? I wonder if it's related to how we import the scss files.
Not much to comment here, I'll read about esModuleInterop.
I like this tests and I think they are important. I have a suggestion here. If we change route to:
We can then change the tests to check for the
It's a great start! I actually have more questions than thoughts. For example:
I prefer multiple small PR rather than a big one. So let's try to keep this one reasonable size and then move on to the next. Sorry for the big reply and thanks for the PR 😄 |
Codecov Report
@@ Coverage Diff @@
## master #596 +/- ##
==========================================
- Coverage 74.92% 74.81% -0.11%
==========================================
Files 100 100
Lines 6423 6426 +3
==========================================
- Hits 4812 4807 -5
- Misses 1260 1272 +12
+ Partials 351 347 -4
Continue to review full report at Codecov.
|
Ah! So it seems like the main issue was the use of the function to dynamically generate a loadable page/imports. My guess is that since the resolve path/component wasn't static Webpack was having a hard time splitting the code into chunks, leading to the creation of 63 chunks. Once I created a statically defined set of AsyncPages I'm now getting 17 chunks (which corresponds to one per page). That said, I haven't played with webpack directly too much, so it's possible I'm still missing something or drawing incorrect conclusions. I still think some caution will be required when dealing with the barrel imports, at least in the non-dynamically imported areas of the application. For example you can break the current code splitting by changing the ErrorBoundary import ErrorPage statement to use To address the other questions:
Let me know what you think! Sorry about the snafu with the first go around! |
Great progress, It's looking better now! I have updated #588 with what I believe we can have as separate PR's. Have a look and let me know what you think. For this PR:
Thank you! |
Sounds good! I'll look into these tonight - thanks again! |
How's this look? Thanks again! |
I need to give it a try and test it. I'm not sure if this CDN setup will work. The reason being that both nonce and the assets base URL are not static nor known during webpack build time. Both values are only available during runtime. If I'm not mistaken, the assetsURL is available on I'll be offline until tuesday/wednesday, so my responses will be delayed. Sorry about that and thanks for the update 😄 |
After merging esInterop, the CI run didn't code split at all. By the way, have you seen that React 16.6 has been released with a native option for code splitting? We could give that a try and remove the extra react-loadable dependency. What do you think? As for the CDN, if you merge master into your branch, you'll be able to use two new properties:
|
Hmm, I'm wondering if esInterop breaks code splitting (not entirely sure what all it does under the hood to create the default imports) - haven't really found consistent documentation to that effect stating it one way or another though. I'll try to spend some more time doing more research on it. I'd definitely agree with using the language built in lazy loader if it works without issue - no sense adding another dependency to the project! And awesome! I'll update the webpack vars accordingly in the index.tsx file. |
Code splitting is working again (goofed in the esInterop PR and didn't remove the use of @fider/pages to import the error page in ErrorBoundary) and I've tried adding the globalAssetPath/contextID from Fider. The React types don't yet include type information for Suspense/Lazy - did you still want to include those now with some ignore flags or just wait until the next types/react release and migrate to Suspense/Lazy then? |
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.
Awesome! I had to tweak a bit the public_path variable to make the CDN work.
I left a few things we need to change and then we can merge this.
Let's keep the Suspense/Lazy for another PR. I just saw the docs and the component needs to be exported as default, which we don't usually do on Fider. So that'll require a slightly bigger change and simply replacing react-loadable with lazy. This PR is already extremely useful, so let's get this into master 😄
Alright, I believe I have those changes integrated. Let me know if there's anything else you want me to change! Thanks again for all your patience, especially with the webpack nonce and asset path! |
It's merged 🎉 Thank you for another great PR! |
Issue: Initial implementation for Issue #588 to add Code Splitting to reduce overall bundle size.
Notable changes in this PR:
Comments/Future Work:
@goenning Did you have any thoughts on the current code splitting implementation? I figured I'd check in with an initial implementation of the code splitting and see what direction we should take it from here. I'd be happy to open another PR if we wanted to tweak the current import style/further prune down the bundle size.