PHPackages                             savinmikhail/dist-size-optimizer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. savinmikhail/dist-size-optimizer

ActiveLibrary[Testing &amp; Quality](/categories/testing)

savinmikhail/dist-size-optimizer
================================

Optimizes your package distribution size by automatically managing .gitattributes export-ignore rules

v0.2.7(4mo ago)7344↓73.2%25MITPHPPHP ^8.2CI passing

Since May 8Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/savinmikhail/dist-size-optimizer)[ Packagist](https://packagist.org/packages/savinmikhail/dist-size-optimizer)[ RSS](/packages/savinmikhail-dist-size-optimizer/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (13)Versions (22)Used By (5)

Dist Size Optimizer
===================

[](#dist-size-optimizer)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/2b5fe6cef7b5bd1e3f515778ad07b5d886dfedad6a401f96f5f2b42af6d9aa2f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736176696e6d696b6861696c2f646973742d73697a652d6f7074696d697a65722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/savinmikhail/dist-size-optimizer/?branch=main)[![Code Coverage](https://camo.githubusercontent.com/3d5868dc34a8d92ca7299af2184693b6ea848d1be969a1c7710d63d563ca9a99/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f736176696e6d696b6861696c2f646973742d73697a652d6f7074696d697a65722f6261646765732f636f7665726167652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/savinmikhail/dist-size-optimizer/?branch=main)[![dist-size status](https://camo.githubusercontent.com/70f553497a58b1cbc800a00bb8d8e48e9d84b4ea0558a70620180a0ff1cbeafe/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d253246736176696e6d696b6861696c253246646973742d73697a652d6f7074696d697a65722532466d61696e253246646973742d73697a652d7374617475732e6a736f6e)](https://camo.githubusercontent.com/70f553497a58b1cbc800a00bb8d8e48e9d84b4ea0558a70620180a0ff1cbeafe/68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e743f75726c3d68747470732533412532462532467261772e67697468756275736572636f6e74656e742e636f6d253246736176696e6d696b6861696c253246646973742d73697a652d6f7074696d697a65722532466d61696e253246646973742d73697a652d7374617475732e6a736f6e)

A command-line tool that helps you optimize your package distribution size by automatically managing `.gitattributes` export-ignore rules.

> **Note**: This package was previously known as `export-ignore-check`. The functionality remains the same, but the name better reflects its purpose of optimizing distribution size.

Why?
----

[](#why)

When you publish a package to Packagist, Composer creates a distribution archive using `git archive`. Files and directories that are not needed in production (like tests, documentation, CI configs) should be excluded using `.gitattributes` export-ignore to:

- Reduce package size
- Speed up installation
- Improve CI/CD pipeline performance
- Keep production packages clean

This tool helps you identify what should be excluded and can automatically fix your `.gitattributes` file.

Installation
------------

[](#installation)

1. As composer dependency:

    ```
    composer require --dev savinmikhail/dist-size-optimizer
    ```
2. Or as standalone phar package:

    ```
    box.phar compile
    ./dist-size-optimizer.phar check
    ```

Dist Size Badge
---------------

[](#dist-size-badge)

Show the status of your distribution size with a badge. The badge is green when the package is optimized and red when it needs optimization:

[![dist-size optimized](https://camo.githubusercontent.com/9e0fbc58882eabef09579d67a531760894b4d4c6379360a6a9bc96c5d0c71bd1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646973742d2d73697a652d6f7074696d697a65642d627269676874677265656e)](https://camo.githubusercontent.com/9e0fbc58882eabef09579d67a531760894b4d4c6379360a6a9bc96c5d0c71bd1/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646973742d2d73697a652d6f7074696d697a65642d627269676874677265656e)[![dist-size needs optimization](https://camo.githubusercontent.com/a35387df78e15424f01cd62e17d186be1dad0629adb89fc710f8effd2ff0336a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646973742d2d73697a652d6e656564732532306f7074696d697a6174696f6e2d726564)](https://camo.githubusercontent.com/a35387df78e15424f01cd62e17d186be1dad0629adb89fc710f8effd2ff0336a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f646973742d2d73697a652d6e656564732532306f7074696d697a6174696f6e2d726564)

### Add badge to your project

[](#add-badge-to-your-project)

1. Copy the [dist-size workflow](.github/workflows/dist-size.yml) into your repository.
2. Add the following snippet to your `README.md`, replacing `` and `` with your repository details:

    ```
    ![dist-size status](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com///main/dist-size-status.json)
    ```

The workflow updates `dist-size-status.json`, and the badge reflects your repository's current status.

Usage
-----

[](#usage)

### Check Current Project

[](#check-current-project)

To check your current project (recommended during development):

```
vendor/bin/dist-size-optimizer check
```

This will:

1. Create a git archive of your project (simulating Packagist's distribution)
2. Scan for files that should be excluded
3. Show you what to add to your `.gitattributes` file
4. Automatically append the suggested patterns to your `.gitattributes` file

> **Note**: When checking your current project, the tool uses `git archive HEAD`, which means it only includes committed changes. Make sure to commit your changes before running the check to get accurate results.

### Check Any Package

[](#check-any-package)

To check any package from Packagist:

```
vendor/bin/dist-size-optimizer check vendor/package
```

For example:

```
vendor/bin/dist-size-optimizer check symfony/console
```

### Clean .gitattributes

[](#clean-gitattributes)

If your `.gitattributes` file contains stale `export-ignore` entries copied from other projects, you can remove all non-existent paths with:

```
vendor/bin/dist-size-optimizer check --clean
```

This command will:

1. Read your existing `.gitattributes` file
2. Remove all lines with `export-ignore` patterns that no longer match any file or directory in the project
3. Overwrite `.gitattributes` with the cleaned content

### Output Options

[](#output-options)

#### Dry Run

[](#dry-run)

By default, the tool will automatically append suggested patterns to your `.gitattributes` file. Use `--dry-run` to only see what would be added without making any changes:

```
vendor/bin/dist-size-optimizer check --dry-run
```

#### JSON Output

[](#json-output)

Add `--json` flag to get machine-readable output:

```
vendor/bin/dist-size-optimizer check --json
```

#### Custom Config

[](#custom-config)

By default, the tool uses a predefined set of patterns to check. You can provide your own config file:

```
vendor/bin/dist-size-optimizer check --config=/path/to/config.php
# or using short option
vendor/bin/dist-size-optimizer check -c /path/to/config.php
```

The config file should be a PHP file that returns an array of patterns to check:

```
