Thanks @filipenevola, I must have another problem then because I do not have any undirect import in my code and still have this huge bundle.
Very weird, I have try removing dependencies that might cause problems but I still have the same size
Installing MUI as a local NPM and commenting the exports of all components I donāt use shaved off 200kb from the @mui/material library. I couldnāt find any other way to do it.
Iāve been through that and imported everything as a direct import. I even used the babel plugins recommended on the MUI website. I just couldnāt get rid of the unused components. This seems to be a problem in Webpack too as Iāve seen in many posts.
I managed to take @mui/material down from 570kb to 360kb.
Also these need to be imported from their right folders:
import { ThemeProvider, useTheme } from '@mui/material/styles'
import useMediaQuery from '@mui/material/useMediaQuery'
Thatās a very interesting dynamic component load. The problem with MUI is that it has so many bits and pieces, not sure it would be feasible to fetch them all through a function (if we would just build the fetching system to receive the component name as a parameter in a function)
There is another way, to avoid MUI down the code until after the router and load all routes dynamically and so MUI would be fetched dynamically within a route component but ā¦
My ābundle strategyā is to put as much as possible and as little as possible into the initial bundle. Projects in early development tend to have a lot of code updates and when you get the user volumes you probably want to serve them, bandwidth wise, from the CDN rather than pushing code from your Node servers.
Ideally: CDN ā Local cacheing with service worker ā consume.
Letās say, you have a 200kb that you need to give to the user in the form of MUI. You can provid it split (from Node), full MUI (from Node) or full MUI (from CDN) within your Meteor bundle.
When traffic increases 200kb easily turns into 10GB and while dynamic imports are ālocalā, you get them from where the Node servers are, CDN-ing puts the edge near the user globally and not only the speed is far better but the cost is much lower. Serving regional CDN is much cheaper than EC2 bandwidth (in the case of AWS).
Then if you SSR thousands of pages and deliver gigs of dynamic imports to new visits you end up spinning more and more cloud servers.
Ok ā¦ this turns into a novel now :))) . I think for the case of MUI I personally just want to remove the ājunkā that comes with it in terms of useless components and theme presets and in general I am looking to get more and more NPM (or code in general) from private CDNs.
Code splitting is great but until we CDN those mini bundles the cost of this performance gain is too hign IMHO.
Thatās a great explanation and already a little a guide here. I think it all depends on expected target audience size. @storyteller might an interesting input for a scaling guide
I saw that but I donāt know why it happened as I never touched this package nor did I find any relations of it to the dynamic import or usage of such.
Yes, I would bet on resuming this PR after merging Meteor 3 to develop branch.
At the time, this PR was really close, so itās worth investing in the final solution for production bundles.
If we focus on having tree-shaking only for production, the work left shouldnāt be that hard or long.
Now, if we want to use tree-shaking in development, then itās another topic, as this code will slow down the development process with Meteor even more.
Do you agree, or do you see another way of achieving what you need?