Skip to content
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

speed up build by fixing mui imports #189

Closed
wants to merge 1 commit into from
Closed

Conversation

mattcasey
Copy link
Contributor

@mattcasey mattcasey commented Mar 7, 2022

You're supposed to import MUI components individually, but I know this is had to remember, it's ugly, and hard to enforce:

import Box from '@mui/material/Box';
vs
import { Box } from '@mui/material';

See: https://mui.com/guides/minimizing-bundle-size/

The next.js maintainers believe this is part of why dev can take so long: vercel/next.js#29559. THey suggest using a special babel plugin, however that means you can't use the SWC compiler (written in Rust and much faster). So I found someone created a similar plugin and implemented that instead. Seems to be working, although the final build size has not changed, I Noticed that mentions of "@mui/icons-material" went from almost 10,000 to about 150 in the '.next/trace' file.

Another alternative is to use babel compiler with this config: https://mui.com/guides/minimizing-bundle-size/#option-2. I haven't tried it yet, but we'd be have do swap the Rust compiler (SWC) with babel, which is slower.

@mattcasey mattcasey added the work-in-progress Not ready for review label Mar 8, 2022
@Devorein
Copy link
Member

Devorein commented Mar 8, 2022

Yeah the issue is that vscode auto-import doesn't show that as an option most of the time. I agree about not choosing Babel over SWC, we should definitely choose Rust over JS.

@mattcasey
Copy link
Contributor Author

OK I went off the deep end and realized that next's swc loader is not passing down the plugin option. SO I opened a PR there: vercel/next.js#35156

@mattcasey
Copy link
Contributor Author

Apparently that 'plugin' is just an swc-loader feature, but next.js is working on a better fix here: vercel/next.js#34969

@mattcasey mattcasey closed this Mar 10, 2022
@mattcasey mattcasey deleted the speedup-build branch May 17, 2022 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
work-in-progress Not ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants