siddharthkp/cost-of-modules

Only output total size?

Siilwyn opened this issue ยท 3 comments

๐Ÿ‘‹ would you accept at PR that adds a flag to only output the total size? I want to run this module from in a CI task and fail if the total size goes about a certain number. Couldn't find any module that does this out of the box.

It seems your need is fulfilled by https://github.com/siddharthkp/bundlesize. Have you checked it out?

@alshakero sadly not, it doesn't include the node modules.

@Siilwyn Hey! This is not something cost-of-modules is good for.

You might like dirsize or get-folder-size

You would already install node_modules in your CI, you can run these on the CLI or with a script:

#!/usr/bin/env node

const getSize = require('get-folder-size') // gives size in bytes
const bytes = require('bytes')

const limit = process.argv[2] // accept size as a parameter
const limitInBytes = bytes(limit, { unit: 'B' })

getSize('node_modules', (err, size) => {
  if (size > limitInBytes) {
    console.error('whoa whoa whoa hold it right here')
    process.exit(1)
  }
})

You can use the above with node size-test 150MB