Are first load JS route stats output to a file?
Unanswered
Northern Goshawk posted this in #help-forum
Northern GoshawkOP
For instance this output
I don't think there's any way of writing those stats to a file in say the
Route (app) Size First Load JS
┌ ○ / 145 B 82 kB
├ ○ /_not-found 869 B 82.7 kB
├ λ /[slug] 145 B 82 kB
├ λ /api/test 0 B 0 B
├ λ /api/test/test2 0 B 0 B
â”” â—‹ /static 145 B 82 kB
+ First Load JS shared by all 81.8 kB
├ chunks/938-5e061ba0d46125b1.js 26.7 kB
├ chunks/fd9d1056-735d320b4b8745cb.js 53.3 kB
├ chunks/main-app-e70e3644c45bd540.js 220 B
â”” chunks/webpack-7f3c39ccc24bf838.js 1.65 kBI don't think there's any way of writing those stats to a file in say the
.next directory is there? Ideally JSON format. It's not a feature of @next/bundle-analyzer30 Replies
Northern GoshawkOP
My thoughts are related to a possible feature request. One could possibly use this information to test against previous builds and see if there are any adverse findings. If a
I'm not sure if people would use this or find this beneficial.
first load js delta increases by a certain threshold percentage/amount that a CI pipeline could warn or error to alert the devs something weird may have happened.I'm not sure if people would use this or find this beneficial.
@Northern Goshawk
I'm not sure how this works in the latest app dir
but I can provide some tips that will hopefuly get you on track
the info you're looking for will be inside the .next folder
after a build is compelted
There is code in here that shows how to parse this data for the old pages directory
You could adapt a similiar approach for the app dir
you'll need to poke around the .next folder after a build occurs
and see where this data lives
You can also dig around the source code of next
and figure out how they rendering these stats as part of the build
Another approach
or rather, an indirect approach
is by piping the stdout of next build into a plain text file
and then just parse/regex out the build stats
Throw it at chatgpt and ask it to craft some regex / parser code
for the nextjs build output
Please let me know what you come up with, if you don't I might expand the next-build-size package with this functionality in the future for the app dir specifically
Northern GoshawkOP
This is nice @linesofcode, it's kind of exactly what I'm talking about, lucky that you're around to see my post.
I think the
I checked the code last night, and it looks like it builds the output here:
https://github.com/vercel/next.js/blob/93eb32d96a05f5254cc2c3e7b8f47e499517e397/packages/next/src/build/utils.ts#L456C10-L456C22
Although I didn't really dig deep into things.
I was curious if I was missing it in the
Stdout is one approach but it could be brittle as it relies on Next.js not breaking it.
It seems like you are/were interested in this for Page Router, so that's cool, it isn't just me 😆. I'd like to see if this is an interest for more people. I think it would have to be part of the Next Bundler or like you said capture the output. I'd say pay attention to this thread, I might create a discussion on GitHub. I'll ping here if I do so.
Thanks again @linesofcode
I think the
.next directory doesn't have that data for App Dir. I checked in various ways but didn't see it.I checked the code last night, and it looks like it builds the output here:
https://github.com/vercel/next.js/blob/93eb32d96a05f5254cc2c3e7b8f47e499517e397/packages/next/src/build/utils.ts#L456C10-L456C22
Although I didn't really dig deep into things.
I was curious if I was missing it in the
.next directory but also if there was a way that I wasn't aware of. I don't think there is.Stdout is one approach but it could be brittle as it relies on Next.js not breaking it.
It seems like you are/were interested in this for Page Router, so that's cool, it isn't just me 😆. I'd like to see if this is an interest for more people. I think it would have to be part of the Next Bundler or like you said capture the output. I'd say pay attention to this thread, I might create a discussion on GitHub. I'll ping here if I do so.
Thanks again @linesofcode
Sounds good!
I'll circle back around to this in the near future and do some research too
this function looks like a good clue
it accepts a build manifest
which i believe is one of the files in the .next output
Northern GoshawkOP
Yeah I think I'll try figuring out what that buildManifest is tomorrow. It's possible there may already be a way.
@Northern Goshawk hey, I'm curious if you found a solution for this?
Northern GoshawkOP
Hey @linesofcode sorry for missing this message. I didn't bother investigating further at this time. If this is something you want to run with, feel free to continue. If you do, ping me in any discussion as I'd like to hear other's thoughts 😀.