Socket
Socket
Sign inDemoInstall

size-limit

Package Overview
Dependencies
7
Maintainers
1
Versions
174
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    size-limit

Show package size and return error if it is bigger than limits allow


Version published
Weekly downloads
209K
decreased by-0.87%
Maintainers
1
Created
Weekly downloads
 

Package description

What is size-limit?

Size Limit is a performance monitoring tool for JavaScript projects. It helps you keep your project within a specific size limit by analyzing the size of your JavaScript bundles and providing warnings when the size exceeds the specified limit.

What are size-limit's main functionalities?

Bundle Size Analysis

This feature allows you to specify the path to your JavaScript bundle and set a size limit. Size Limit will analyze the bundle and ensure it does not exceed the specified limit.

module.exports = [
  {
    path: 'dist/bundle.js',
    limit: '500 KB'
  }
];

Custom Configurations

You can customize the analysis by enabling gzip compression or disabling the running of the bundle. This provides more flexibility in how you measure the size of your bundles.

module.exports = [
  {
    path: 'dist/bundle.js',
    limit: '500 KB',
    gzip: true,
    running: false
  }
];

Multiple Bundles

Size Limit supports analyzing multiple bundles in a single configuration. This is useful for projects with multiple entry points or output files.

module.exports = [
  {
    path: 'dist/bundle1.js',
    limit: '300 KB'
  },
  {
    path: 'dist/bundle2.js',
    limit: '200 KB'
  }
];

Other packages similar to size-limit

Changelog

Source

0.1.1

  • Fix parsing B unit without kilo/mega prefix.

0.1

  • Initial release.

Readme

Source

Size Limit

Show how many kilobytes your JS library will add to a user bundle.

You can add this tool to Travis CI and set the limit. If you accidentally add a very big dependency, Size Limit will throw an error.

Size Limit example

Sponsored by Evil Martians

Usage

Install size-limit:

$ npm install --save-dev size-limit

Get current project size:

$ ./node_modules/bin/size-limit

  Package size: 8.46 KB
  With all dependencies, minifier and gzipped

If project size looks to big run Webpack Bundle Analyzer:

./node_modules/bin/size-limit --why

Add some bytes to current size to get the limit by adding npm run script to package.json:

  "scripts": {
    "test": "jest && eslint .",
+    "size": "size-limit 9KB"
  }

Add size script to tests:

  "scripts": {
-    "test": "jest && eslint .",
+    "test": "jest && eslint . && npm run size",
    "size": "size-limit 9KB"
  }

Don’t forget to add Travis CI to your project.

JS API

const getSize = require('size-limit')

const index = path.join(__dirname, 'index.js')
const extra = path.join(__dirname, 'extra.js')

getSize([index, extra]).then(size => {
  if (size > 1 * 1024 * 1024) {
    console.error('Project become bigger than 1MB')
  }
})

Keywords

FAQs

Last updated on 26 Jun 2017

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc