-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
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
[build] Bundling with Rollup #10212
Comments
@NMinhNguyen The I thought we were already applying these transforms for the
Same concern than above. I don't think it's wise to publish different versions of our components. It's gonna bloat users bundle when using third party libraries based on Material-UI. You can already experience the issue with lodash (lodash/x, lodash-es/x, lodash.x).
Could it be a Rollup issue? |
@oliviertassinari Could you please elaborate on what you meant? Correct me if I'm wrong, but I think the analogy with
Do you mean when the user imports a CJS module, but then a library they use imports an ES module?
So Rollup is primarily an ES module-aware bundler. There is rollup-plugin-commonjs which is used to
But it is not able to figure out the named exports in all cases, which is when you need to specify the |
Modules don't need to be in different packages to introduce duplication in users bundle. Simply the
They are much smaller libraries. Duplication tolerance is higher for them.
Babel doesn't traverse the
Yes, or the other way around.
I believe it's working with webpack. |
@oliviertassinari Sorry, I wasn't very clear. I was actually referring to other libraries writing
I still have a feeling that if a library ensures that its ES output only imports ES modules, then the risk of module duplication is significantly reduced? Happy to be proved wrong though. I guess given your response, we can close out this issue? And to solve the problem of other libraries having to apply the same production-mode Babel transforms on |
@NMinhNguyen Yes, I agree with this point at the condition all the third party libraries you want to use follow this pattern. Hard to enforce.
Yes, please! I thought it was already done. It can be considered a bug on our end. |
If the
Node.js is going with a This may actually also solve the duplication issue with libraries. Because if you import Would you be happy with including a The only caveat I can think of is that we'd need to check and make sure all our modules are valid ESM modules and won't break when run server side in Node 10.0. |
I would definitely like to see I shave 20% of the bundle size of Material-UI, and 35% more off material-ui-icons, just by using an alias to tell WebPack to import the |
@dantman I agree, it would be great. |
Also the Minimizing Bundle Size explicitly says:
Which is why I never bothered setting it up and made a bug report when things weren't tree shaking correctly. If the consensus is that tree shaking doesn't actually work, even when we do everything right, and the response to any bugs about tree shaking is to try the alternatives. Then the documentation should be updated to recommend users use the alternatives instead of dissuading users who are happy to configure tree shaking from doing so. |
fwiw, here's a different experience and motivation: When using dynamic bundle loading, initial page-load gains can be very much larger than those @dantman's showing above. My initial load mui stat size for about half of my pages is about 300K (30K gzipped). The other half need another bundle, with another 300K (22K gzipped) of mui. A few rarely-used components are sprinkled elsewhere in bundles where they are used. I'm just telling webpack 4 to split things up as it deems best; I'm not hand-tweaking all of this. I'm trying to keep the app viable for use on slow devices with low bandwidth. |
Expected Behavior
Bundling with Rollup should work as long as MUI provides ES modules (https://github.com/rollup/rollup/wiki/ES6-modules#es6-friendly-libraries).
Current Behavior
Currently, there is an
index.es.js
file which is an ES module itself, but it points at CommonJS modules (https://unpkg.com/[email protected]/index.es.js). This then causes Rollup to fail to build:Presumably, this is because https://github.com/rollup/rollup-plugin-commonjs cannot fully understand the CommonJS exports (unless you manually specify them via
namedExports
option).Steps to Reproduce (for bugs)
I have a simple repro available here: https://github.com/NMinhNguyen/material-ui-rollup-example
It also contains a branch where I modified
yarn.lock
to point at a temporary fork of MUI that publishes ES modules (source), and bundling with Rollup works without any other changes. I am willing to raise a PR with this change (I'll probably also replace the currentbuild:es2015modules
script as I believe my change supersedes it, but not sure if removingindex.es.js
could be considered a breaking change?), but I thought I'd raise an issue first (this is also what the contributing guide suggests) 🙂I have also created this branch where I committed the current build output and how it changes with my changes so you can more easily review them as well as spot any possible regressions. And here you can find the actual ES5 modules.
By the way, the reason I would rather not use the
es
folder is because that folder is ESNext (2015+), so I'd have to transpile it via Babel myself. This would mean that I'd additionally have to include these plugins to ensure I get the same Babel transformations applied: https://github.com/mui-org/material-ui/blob/8497cd976d74cfd102c6e8afb932348b366dd5b3/.babelrc#L70-L83Context
We are using Rollup to bundle our code.
Your Environment
The text was updated successfully, but these errors were encountered: