Multimedia Engineer
We’re working in a monorepo with Turbo, where multiple Next.js applications are located in the apps
folder.
We have a shared component library in the packages
folder that is used across all these applications.
The development process was being slowed down due to incorrect imports of Material UI Icons in the component library, impacting performance significantly.
The trailing slash at the end of the import path forces the entire package to be imported instead of just the necessary icons.
Each Next.js app was loading and compiling thousands of unnecessary modules, making the development environment slow and heavy for the machine.
CheckBox,
CheckBoxOutlinedBlack
and InfoOutlined it pulls all icons from Material UI, preventing tree shaking from working correctly.Tree-shaking is a technique used in modern web development to eliminate unused code (dead code) from the final bundle. It can significantly reduce the size of the bundle, resulting in faster load times and better performance.
Dead code refers to the code that is not executed or used during runtime. For example, if a module exports a function that is never called in the application, then that function is considered dead code.
Without Tree Shaking you’re pulling in unnecessary code, which:
- Increases bundle size.
- Slows down compilation.
- Causes longer load times.
Optimizing Imports:
Additional Optimization in Next.js:
optimizePackageImports
setting in Next.js to handle the packages imported from the packages
folder efficiently.Instead of grabbing the whole Lego set, we only select the exact pieces we need—this is like optimizing imports.
-63.2%
-82%
-85.7%
Raw size generated by Webpack.
Size of the file in the browser memory when it is being executed.
Size of the file when compressed to reduce weight in network transfer.
Time Savings:
Cost Savings:
Multimedia Engineer