PHPackages                             halimjr/asset-minifier-bundle - 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. halimjr/asset-minifier-bundle

ActiveSymfony-bundle

halimjr/asset-minifier-bundle
=============================

Zero-dependency JS minification for Symfony Asset Mapper — powered by esbuild, no Node.js or npm required.

v1.5.0(1mo ago)07↑328.6%[1 issues](https://github.com/halimjr/asset-minifier-bundle/issues)MITPHPPHP &gt;=8.1CI passing

Since Mar 21Pushed 1mo agoCompare

[ Source](https://github.com/halimjr/asset-minifier-bundle)[ Packagist](https://packagist.org/packages/halimjr/asset-minifier-bundle)[ RSS](/packages/halimjr-asset-minifier-bundle/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (9)Versions (7)Used By (0)

Asset Minifier Bundle
=====================

[](#asset-minifier-bundle)

A companion bundle for [Symfony Asset Mapper](https://symfony.com/doc/current/frontend/asset_mapper.html) that automatically minifies your JavaScript using [esbuild](https://esbuild.github.io/) — with no Node.js, no npm, and no build pipeline to configure.

Asset Mapper already handles import maps, cache-busting hashes, and ES module loading. This bundle completes the picture by shrinking your JS before it ships.

Why this bundle?
----------------

[](#why-this-bundle)

Symfony Asset Mapper is deliberately free of Node.js tooling. But without a minification step, your JavaScript ships as readable source code — variable names, comments, and whitespace included. This bundle fills that gap by running each JS file through esbuild at compile time, using a self-contained binary that PHP downloads and manages for you.

No `package.json`. No `node_modules`. No extra tooling to maintain.

Requirements
------------

[](#requirements)

- PHP 8.1+
- `ext-phar` and `ext-zlib` (enabled by default in standard PHP builds)
- Symfony 6.3 or 7.x with `symfony/asset-mapper`

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

[](#installation)

```
composer require halimjr/asset-minifier-bundle
```

Register the bundle in `config/bundles.php`:

```
return [
    // ...
    HalimJr\AssetMinifierBundle\AssetMinifierBundle::class => ['all' => true],
];
```

That's the entire setup. On the next `php bin/console asset-map:compile`, the esbuild binary is downloaded automatically and all your JavaScript assets are minified.

Benchmarks
----------

[](#benchmarks)

Measured on a real Symfony application with 45 Stimulus controllers:

FileOriginalMinifiedReduction`main_controller.js`66.8 KB38.7 KB**42%**`list_controller.js`27.1 KB16.2 KB**40%**`detail_controller.js`20.1 KB11.8 KB**41%**`sync_controller.js`16.2 KB9.4 KB**42%**`alert_controller.js`14.3 KB8.5 KB**41%****Total (45 controllers)****419 KB****308 KB****~42%**Minification includes whitespace removal, comment stripping, and identifier mangling (local variable names shortened to single characters).

How it works
------------

[](#how-it-works)

The bundle registers a compiler with Symfony Asset Mapper's pipeline via `AssetCompilerInterface`. During compilation, each of your JavaScript files is piped through esbuild with `--minify --format=esm`, which performs:

- **Whitespace and comment removal**
- **Identifier mangling** — local variable names are shortened to single characters
- **Dead-code elimination** — unreachable branches are removed

The esbuild binary (~5 MB compressed) is downloaded once from the npm registry and cached in `var/esbuild/`. It is version-pinned by the bundle and re-downloaded automatically when you upgrade to a bundle version that ships a newer esbuild release.

**Binary trust model.** The download uses HTTPS with TLS peer verification (the same trust model as every `npm install`). Additionally, the bundle fetches the expected SHA-512 hash from the npm registry metadata API and verifies the tarball before extraction. If the hash does not match, the download is rejected and the binary is never written to disk.

**Vendor assets are intentionally skipped.** Pre-minified packages managed via importmap (e.g. `@hotwired/stimulus`, `apexcharts`) pass through untouched.

**Stimulus controllers are safe.** The bundle runs after Symfony's `JavaScriptImportPathCompiler`, so import paths are resolved and registered in the importmap before minification occurs. Method names used in `data-action` attributes are not mangled.

Configuration
-------------

[](#configuration)

No configuration is required for standard use. The following options are available if you need them:

```
# config/packages/asset_minifier.yaml
asset_minifier:
    esbuild_version: '0.25.2'  # pin to a specific esbuild version
    binary_path: null           # use a pre-existing binary instead of downloading
    source_maps: false          # set to true to embed inline source maps for production debugging
```

### Source maps

[](#source-maps)

When `source_maps: true`, an inline source map is appended to each minified file. This lets you see original variable names and line numbers in browser DevTools, which is useful for debugging production issues without deploying unminified code.

Note that inline source maps increase file size. For most projects the trade-off is worth it in staging environments; in production, leave it disabled (the default).

`binary_path` is useful in environments where downloading from the npm registry is restricted, or when you manage the esbuild binary through your own provisioning (e.g. system packages, CI cache layers, Docker images).

Commands
--------

[](#commands)

CommandDescription`asset-minifier:download`Downloads the esbuild binary for the current platform`asset-minifier:download --dry-run`Previews what would be downloaded without downloadingDeployment
----------

[](#deployment)

### GitHub Actions

[](#github-actions)

```
- name: Install PHP dependencies
  run: composer install --no-dev --optimize-autoloader

- name: Download esbuild
  run: php bin/console asset-minifier:download

- name: Compile assets
  run: php bin/console asset-map:compile --env=prod
```

### GitLab CI

[](#gitlab-ci)

```
deploy:
  script:
    - composer install --no-dev --optimize-autoloader
    - php bin/console asset-minifier:download
    - php bin/console asset-map:compile --env=prod
    - php bin/console cache:clear --env=prod
```

### Docker

[](#docker)

If your container's application directory is read-only, `var/esbuild/` cannot be written at runtime. Download the binary during the image build step instead:

```
RUN composer install --no-dev --optimize-autoloader
RUN php bin/console asset-minifier:download --env=prod
RUN php bin/console asset-map:compile --env=prod
```

Alternatively, place the binary at a writable or pre-provisioned path and tell the bundle where it is:

```
# config/packages/prod/asset_minifier.yaml
asset_minifier:
    binary_path: /usr/local/bin/esbuild
```

When `binary_path` is set, the bundle uses that binary directly and never attempts a download.

### General deploy script

[](#general-deploy-script)

```
composer install --no-dev --optimize-autoloader
php bin/console asset-minifier:download
php bin/console asset-map:compile --env=prod
php bin/console cache:clear --env=prod
```

The download command is idempotent — it does nothing if the correct binary version is already present. You can safely run it on every deploy.

Add the binary directory to `.gitignore`:

```
/var/esbuild/

```

Supported platforms
-------------------

[](#supported-platforms)

OSx86\_64arm64Linux✓✓macOS✓✓Windows✓✓Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome at [github.com/halimjr/asset-minifier-bundle](https://github.com/halimjr/asset-minifier-bundle).

License
-------

[](#license)

MIT — see [LICENSE](LICENSE).

###  Health Score

41

—

FairBetter than 88% of packages

Maintenance97

Actively maintained with recent releases

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity46

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

6

Last Release

49d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9e0c4f34ce2baa444b165a7b5320c49681d7ea83e2faf99776578c3400490ab7?d=identicon)[halimjr](/maintainers/halimjr)

---

Top Contributors

[![halimjr](https://avatars.githubusercontent.com/u/29090378?v=4)](https://github.com/halimjr "halimjr (8 commits)")

---

Tags

symfonybundlejavascriptminifyasset-mapperesbuild

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/halimjr-asset-minifier-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/halimjr-asset-minifier-bundle/health.svg)](https://phpackages.com/packages/halimjr-asset-minifier-bundle)
```

###  Alternatives

[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M151](/packages/sulu-sulu)[sensiolabs/gotenberg-bundle

A Symfony bundle that provides seamless integration with Gotenberg for generating PDFs and screenshots from various sources (HTML, Markdown, Office documents, URLs) with a clean, builder-based API.

210210.4k2](/packages/sensiolabs-gotenberg-bundle)[spomky-labs/pwa-bundle

Progressive Web App Manifest Generator Bundle for Symfony.

6144.4k1](/packages/spomky-labs-pwa-bundle)[cmsig/seal-symfony-bundle

An integration of CMS-IG SEAL search abstraction into Symfony Framework.

15195.8k5](/packages/cmsig-seal-symfony-bundle)[php-flasher/flasher-symfony

Integrate flash notifications into Symfony projects effortlessly with PHPFlasher. Improve user experience and application feedback loops easily.

141.3M19](/packages/php-flasher-flasher-symfony)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
