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

Display bundle sizes after build #876

Closed
thisbejim opened this issue Jan 25, 2017 · 27 comments · Fixed by #5442
Closed

Display bundle sizes after build #876

thisbejim opened this issue Jan 25, 2017 · 27 comments · Fixed by #5442
Labels
good first issue Easy to fix issues, good for newcomers

Comments

@thisbejim
Copy link

It would be great to see bundle sizes in the terminal after building a project, similar to the output of a create-react-app build.

@arunoda arunoda added Nice to have good first issue Easy to fix issues, good for newcomers labels Jan 25, 2017
@ntwcklng
Copy link
Contributor

ntwcklng commented Jan 25, 2017

We could use a table formatter like https://github.com/Automattic/cli-table for this
I've created a draft which looks pretty nice:

1:
screenshot at jan 25 13-29-31

2:
screenshot at jan 25 15-18-48

Any other ideas?

@arunoda
Copy link
Contributor

arunoda commented Jan 25, 2017

This looks great. But this list could grow since we might have more pages. Here's my suggestion.

  • Use a simple list rather a table. (It saves space)
  • Only show top 5 files (or some good amount)
  • When showing pages, show pages/about.json like that.
  • I prefer the first design for the uncompressed and gzipped sizes
  • May be it's better to show the time spend for the build (and time for webpack and time for gzipping)

@transcranial
Copy link

why not use https://github.com/FormidableLabs/webpack-dashboard?

@ntwcklng
Copy link
Contributor

@arunoda why do we have to save space? A list would take as much space as the table - if we want to display it readable (sizes on the same tab etc.)
I think this table is the perfect solution for outputting data like the bundle size.
To make it more compact, we can adjust the padding/margin from the cells.

For me, this is the perfect example how not to do it:

@transcranial this dashboard is maybe helpful when running next in dev mode. However, when you run next build you just need a lightweight list/table

@sedubois
Copy link
Contributor

@ntwcklng I think he just means that the horizontal lines in the table aren't needed, they take up vertical space

@ntwcklng
Copy link
Contributor

Okay, the alternative is console.table
Looks also pretty nice
screenshot at jan 25 20-06-12

Should we log the 5 overall largest files, or all bundle files + the 3 largest in pages/?

@arunoda
Copy link
Contributor

arunoda commented Jan 25, 2017

@ntwcklng this looks pretty nice.
Shall we sort (z-a) by the size.
Ignore _document.json. It's a server only file.

@arunoda
Copy link
Contributor

arunoda commented Jan 25, 2017

all bundle files + the 3 largest in pages/?

I like this.

@sakulstra
Copy link
Contributor

sakulstra commented Jan 26, 2017

I'd love to see this, but why restrict the output to ~5pages?
The project i'm working on has only ~10 and it would make sense for me to monitor the size for all of them.

Btw. would it be possible to not only display the size, but also the size difference to the previous build?

main.js    159kB (48.2kB) (+36.4kB)

@arunoda
Copy link
Contributor

arunoda commented Jan 26, 2017

I not against of displaying ~10 pages. But I fear that'll be too much info. In this case, we mostly need to figure out our heavy pages. We need to limit upto few pages.

Btw. would it be possible to not only display the size, but also the size difference to the previous build?

I don't think this is possible. We do this only for production build (it doesn't make sense for the dev build) and it's not (most of the time) possible to compare with the previous bundle.

@ntwcklng
Copy link
Contributor

ntwcklng commented Jan 26, 2017

I don't know if its a good idea to include the path in the output:
screenshot at jan 26 12-43-13

Should we just go with the basename for the pages?

If someone wants to test it: https://github.com/ntwcklng/next.js/tree/log-build-size

@sakulstra
Copy link
Contributor

sakulstra commented Jan 26, 2017

@arunoda but even comparing prouction build sizes(like create-react-app does as far as i know) would help a lot.

With this you can easily detect if you accidentally included the whole e.g. 'firebase' or 'lodash'... without a history the size is just a number, but if you can notice: "since last build my main.js is now 60kb bigger than before you can actually wonder where this comes from and figure out if the increasing file size is reasonable."

@nkzawa
Copy link
Contributor

nkzawa commented Feb 3, 2017

Btw, webpack2 supports options related to this topic.

https://webpack.js.org/configuration/performance/

We disable performance.hints for now.

Additionally, I wonder if this feature can be implemented by a webpack plugin. Ideally, I hope https://github.com/geowarin/friendly-errors-webpack-plugin supports this.

@timneutkens
Copy link
Member

I'm +1 for adding it to friendly-errors-webpack-plugin. Created an issue for it to discuss.

@oliviertassinari
Copy link
Contributor

oliviertassinari commented Dec 13, 2017

For anyone looking into preventing bundle size regression. I have been solving a part of the issue with size-limit running in the CI:

.size-limit

[
  {
    "path": ".next/app.js",
    "webpack": false,
    "limit": "302.1 KB"
  },
  {
    "path": ".next/bundles/pages/www/home.js",
    "webpack": false,
    "limit": "35.4 KB"
  }
]

capture d ecran 2017-12-13 a 16 49 30

@julkue
Copy link

julkue commented Feb 9, 2018

@timneutkens Since geowarin/friendly-errors-webpack-plugin#54 was closed and this ticke too, is there any follow-up ticket about this feature?

@dackers86
Copy link

Also keen to know if there has been any updates to this feature.

ParcelJS also has this and it's proved to be very useful.

@vonwao
Copy link

vonwao commented Apr 3, 2018

What does this ticket have to do with friendly errors? Anyways it looks like that got closed. I hate when tickets get linked to somewhere else and then closed. Seems like everyone liked this idea, why not merge it in?

@typeofweb
Copy link
Contributor

Should this be reopened @timneutkens ?

@timmywil
Copy link
Contributor

timmywil commented Oct 11, 2018

This ticket died for seemingly no reason. You can set config.performance to "error" to see the output for production builds in your next.config.js. However, the formatting is lost and it's just printed as an array of strings.

@timneutkens Would be great to either have an option to show webpack output during the build or have a hook for handling build errors so we can print these messages to the console (since webpack already made them pretty but they're stuck in an array).

Edit: Was just looking over the build code. Perhaps this could be addressed by printing the errors (and warnings?) from webpack stats individually in runCompiler. Then this could be closed by pointing to webpack performance hints. For instance, something like this...

if (jsonStats.errors.length > 0) {
  console.log()
  console.error.apply(console, jsonStats.errors)
  console.log.apply(console, jsonStats.warnings)
  // Don't include jsonStats in the error or it would just print it again when thrown
  return reject(new Error('Soft errors from webpack'))
}

@timneutkens
Copy link
Member

Let's re-open it.

@timneutkens timneutkens reopened this Oct 11, 2018
timmywil added a commit to timmywil/next.js that referenced this issue Oct 12, 2018
- Shows warnings even when resolving, to facilitate hints set to 'warning'
- Fixes vercel#876 : Set performance.hints to 'warning' or 'error' in next.config.js
timneutkens pushed a commit that referenced this issue Oct 20, 2018
- Shows warnings even when resolving, to facilitate hints set to 'warning'
- Fixes #876 : Set performance.hints to 'warning' or 'error' in next.config.js
@lucleray
Copy link
Member

I made a small plugin to do show bundle size when running next build. It's quite similar to some suggestions in this issue.

https://github.com/lucleray/next-size

demo of next-size plugin

@timneutkens Do you think it has its place in nextjs or it's better to keep it as a separate package ? create-react-app has something like that by default.

@timneutkens
Copy link
Member

timneutkens commented Nov 12, 2018

I think we should re-open this issue. I kind of don't want to add extra dependencies to Next.js at this point, so can we make it work with 0 dependencies?

@timneutkens timneutkens reopened this Nov 12, 2018
@lucleray
Copy link
Member

@timneutkens It should be possible 🙂

There's 3 dependencies :

  • gzip-size => one line, using node's internal zlib library
  • pretty-bytes => ~5 lines, or maybe there's something like this already in next.js ?
  • chalk => we could "reuse" the dependency in webpackbar with a loose version pin, or just drop the colors

@timneutkens
Copy link
Member

@lucleray sounds great to me, let's remove chalk for now and move those lines into the codebase with a comment referring back to the license

@lucleray
Copy link
Member

Here's the PR : #5664

@timneutkens
Copy link
Member

@lucleray solved this really well 😌

@lock lock bot locked as resolved and limited conversation to collaborators Dec 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
good first issue Easy to fix issues, good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.