Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
October 28, 2021 11:53 pm GMT

How Next.js 12 improved Material-UI app compile by 8X

Some are calling Next.js 12 the "biggest step forward yet." Especially Rust fans.

Next.js 12's new Rust compiler features ~3x faster refresh locally and ~5x faster builds, but that's not the feature that helped me most.

The unsung hero of the release for me was...

Compiled module count!

Next.js now outputs Fast Refresh timing in the console for both client and server compilation, including the number of modules and files compiled.

Image description

10,000 Modules * faint *

10,000 is great if we're talking about Outliers , but downright scary when we're talking about modules.

My application uses Material-UI, but is pretty small, so what happened?!

Take a look:

import Menu from '@mui/icons-material/Menu';import ChevronRight from '@mui/icons-material/ChevronRight';import Save from '@mui/icons-material/Save';

versus:

import { Menu, ChevronRight, Save} from '@mui/icons-material';

The shorter one sure looks prettier, and VSCode even suggests importing from @mui/icons-material first, but don't fall for it!

How does it impact the compile time?

// importing from @mui/icons-materialevent - compiled successfully in 5.1s (10013 modules)// importing from @mui/icons-material/ChevronRightevent - compiled successfully in 615ms (1024 modules)

As a first time Next.js user, I did not have a project to compare against to recognize that my compile times were slow until the new module count logging feature.

If you use Material-UI, be sure to replace any instances of direct imports from @mui/material or @mui/styles as you will be compiling ALL the modules from the entire packages. Watch out for barrel files too!

With 1,000 modules remaining, I still have some improvements to make, but I figured I'd share for any others who may experience the same shock! How many modules does your Next.js application have?

P.S. Thanks for reading my first DEV article!


Original Link: https://dev.to/kyleapex/how-nextjs-12-improved-material-ui-app-compile-by-8x-47nf

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To