Next.js Discord

Discord Forum

Is optimizePackageImports going to be available for pages router?

Unanswered
Cape lion posted this in #help-forum
Open in Discord
Cape lionOP
Hi everyone!

As I understand the new feature optimizePackageImports is only for the "app" router.
https://nextjs.org/docs/app/api-reference/next-config-js/optimizePackageImports

Is the same going to be available for the "pages" router some time soon?
Or is there any alternative way already available to implement in the "pages" router?

I want it mainly for 2 packages: lodash and semantic-ui-react.

Thank you.

18 Replies

from what i understand, it deals with inputs but doeson't care which type type... this is something that you are going to have to test as im not 100% sure....
Cape lionOP
I actually tried in my project with "pages" router, and it didn't work.
So I was wondering if I implemented it wrong or if it's unavailable atm.
and you use latest version?
and when you say that it didn't work, what do you mean
as your example of lodash, is already on the list, so you don't need to do anything
Cape lionOP
Yes, I'm on Next.js version 13.5.2
btw v13.5.3 is latest as of 1hr ago
Cape lionOP
I understand that lodash and a few libraries are already in the list and we don't need to do anything.
But when I analyze the bundle with @next/bundle-analyzer, the lodash gzip is still 22kb.
Also the app-*.js is of same size with or without the optimizePackageImports config.
@riský *btw v13.5.3 is latest as of 1hr ago*
Cape lionOP
Oh, thanks. Let me check with this version.
Cape lionOP
Well I think the gzip size of 22kb is for the full package, similar to what is mentioned on the lodash.com
Full build (~24kB gzipped)
hmm nextjs could be thinking that you are using basicly everything... or not working....
Cape lionOP
Also I found the similar lodash GZIP size from here: https://dev.to/mbernardeau/6-tips-to-optimize-bundle-size-50n9
I must be using <15% of Lodash functions.
so, does that mean that nextjs's optimsation of packages is working?
Cape lionOP
No, the screenshot above shows the full size of Lodash library when analyzed before any optimisations.
So looks like Next.js optimisation is not working for me.
Cape lionOP
Still the same results with 13.5.3 🥹