Search by

core23 / composer-size-limit

core23

Composer plugin to enforce size limits for files, vendor and build artifacts, like npm size-limit.

Package info

github.com/core23/composer-size-limit

Type:composer-plugin

pkg:composer/core23/composer-size-limit

Statistics

Installs: 2

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-11-12 19:30 UTC

This package is not auto-updated.

Last update: 2026-11-13 17:52:25 UTC


README

๐Ÿ“ฆ composer-size-limit

Keep your PHP project lean.
Set size budgets for files, vendor/ and build artifacts, and fail the build when they grow.

PHP Composer License PHPStan

Inspired by npm's size-limit.

โœจ Features

  • ๐ŸŽฏ Budgets per entry: files, directories, globs or your whole vendor/
  • ๐Ÿ—œ๏ธ Real-world sizes: raw bytes, gzip or brotli
  • ๐Ÿงน Production-only vendor/: skip require-dev packages with no-dev
  • ๐Ÿค– CI-ready: exit code 1 on overflow, machine-readable --json
  • ๐Ÿชถ Zero config files: everything lives in your composer.json
  • ๐Ÿ›ก๏ธ Strict validation: typos in keys, bad units or empty matches fail loudly

๐Ÿš€ Quick start

composer require --dev core23/composer-size-limit

Allow the plugin when Composer asks, then add a budget to your composer.json:

{
    "extra": {
        "size-limit": [
            { "name": "Assets", "path": "public/build/**/*.js", "limit": "500 kB", "compression": "gzip" },
            { "name": "Vendor", "path": "vendor", "limit": "20 MB", "no-dev": true }
        ]
    }
}

Run it:

composer size-limit
+--------+----------+-------+-------------+----------+
| Name   | Size     | Limit | Compression | Status   |
+--------+----------+-------+-------------+----------+
| Assets | 312.4 kB | 500 kB| gzip        | OK       |
| Vendor | 24.1 MB  | 20 MB | none        | EXCEEDED |
+--------+----------+-------+-------------+----------+

โš™๏ธ Configuration

Each entry in extra.size-limit supports:

Key Required Default Description
name โœ… โ€“ Label in the report
path โœ… โ€“ File, directory (recursive) or glob, or a list of them
limit โœ… โ€“ Maximum size, e.g. "500 kB", "2 MiB" or plain bytes
compression none none, gzip or brotli (needs ext-brotli)
no-dev false Ignore files of packages that are only in require-dev

๐Ÿ” Paths and globs

Pattern Matches
build/app.phar a single file
vendor every file below the directory
dist/*.js .js files directly in dist/
dist/**/*.js .js files at any depth
dist/*.{js,css} alternatives

Paths are relative to the directory of composer.json. Symlinks are ignored, overlapping paths are counted once, and an entry without any match is an error.

๐Ÿ“ Units

Decimal (ร—1000) Binary (ร—1024)
kB, MB, GB KiB, MiB, GiB

Note

no-dev skips the files of dev-only packages. Composer's generated files in vendor/composer/ (autoloader, installed.json) still describe the installed set, so they grow with your dev dependencies. Pick a vendor limit with that overhead in mind, or measure after composer install --no-dev.

Units are case-insensitive. With gzip or brotli, every file is compressed on its own and the results are summed, just like they would be served over HTTP.

๐Ÿ–ฅ๏ธ Usage

composer size-limit            # table output, exit code 1 if a limit is exceeded
composer size-limit --json     # machine-readable output for CI
composer size-limit --no-dev   # apply "no-dev" to every entry
๐Ÿ“„ JSON output
{
    "passed": false,
    "results": [
        { "name": "Assets", "size": 312400, "limit": 500000, "compression": "gzip", "passed": true },
        { "name": "Vendor", "size": 24100000, "limit": 20000000, "compression": "none", "passed": false }
    ]
}

๐Ÿ”„ Continuous integration

# .github/workflows/size.yml
name: Size limit
on: [pull_request]

jobs:
  size:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: shivammathur/setup-php@v2
        with:
          php-version: '8.3'
      # the plugin is a dev dependency, so install with dev packages
      # and use "no-dev": true on entries that must only count production code
      - run: composer install --prefer-dist
      - run: composer size-limit

๐Ÿงช Development

composer install
composer test   # PHPUnit
composer stan   # PHPStan level 8
composer size-limit   # the plugin checks its own size budget (see extra.size-limit)

๐Ÿ“„ License

MIT