jbsnewmedia/asset-composer-bundle

A Symfony bundle to help you manage your assets

1.1.1 2025-06-02 18:56 UTC

This package is auto-updated.

Last update: 2025-06-02 18:56:32 UTC


README

AssetComposerBundle is a Symfony bundle that helps you manage and serve assets directly from the vendor directory. It ensures all files are kept up-to-date by leveraging file modification timestamps for cache busting.

๐Ÿš€ Features

  • Manage CSS/JS assets via Composer packages
  • Automatic versioning using file timestamps
  • Simple integration with Twig templates
  • Supports production/dev-only assets via assetcomposer.json
  • Symfony 6 & 7 compatible

โš™๏ธ Requirements

  • PHP 8.1 or higher
  • Symfony Framework 6.4 or 7.0

๐Ÿ“ฆ Installation

Use Composer to install the bundle:

composer require jbsnewmedia/asset-composer-bundle

๐Ÿ“‹ Usage

1. Install Asset Packages via Composer

composer require twbs/bootstrap
composer require components/font-awesome
composer require avalynx/avalynx-alert

2. Register Assets in Twig Templates

{% do addAssetComposer('twbs/bootstrap/dist/css/bootstrap.css') %}
{% do addAssetComposer('components/font-awesome/css/all.css') %}
{% do addAssetComposer('avalynx/avalynx-alert/dist/css/avalynx-alert.css') %}
{% do addAssetComposer('avalynx/avalynx-alert/dist/js/avalynx-alert.js') %}

3. Render in Layout

<!DOCTYPE html>
<html>
<head>
    {% block stylesheets %}
        {{ renderAssetComposerStylesheets() }}
    {% endblock %}
</head>
<body>
    {% block body %}{% endblock %}
    
    {% block javascripts %}
        {{ renderAssetComposerJavascripts() }}
    {% endblock %}
    
    {{ renderAssetComposerJavascripts('bottom') }}
</body>
</html>

๐Ÿ“ File Structure

config/
โ”œโ”€โ”€ routes.yaml
โ”œโ”€โ”€ services.yaml
src/
โ”œโ”€โ”€ Controller/
โ”‚   โ””โ”€โ”€ AssetComposerController.php
โ”œโ”€โ”€ DependencyInjection/
โ”‚   โ”œโ”€โ”€ AssetComposerExtension.php
โ”‚   โ””โ”€โ”€ Configuration.php
โ”œโ”€โ”€ Service/
โ”‚   โ””โ”€โ”€ AssetComposer.php
โ”œโ”€โ”€ Twig/
โ”‚   โ””โ”€โ”€ AssetComposerExtension.php
โ”œโ”€โ”€ AssetComposerBundle.php

๐Ÿงฐ Configuration (Optional)

You can create an assetcomposer.json file in your asset packages to define which files should be exposed:

{
  "name": "library-name",
  "files": [
    "dist/css/styles.css",
    "dist/js/scripts.js"
  ],
  "files-dev": [
    "src/css/dev-styles.css",
    "src/js/dev-scripts.js"
  ]
}

๐Ÿ”ง Development Tools

To maintain code quality, this project uses:

  • PHP-CS-Fixer: composer bin-ecs
  • PHPStan: composer bin-phpstan
  • Rector: composer bin-rector

Install and update tools using:

composer bin ecs install
composer bin phpstan install
composer bin rector install

๐Ÿงช Testing & QA

All code adheres to modern PHP standards. Use the provided scripts to analyze and refactor the codebase:

composer bin-phpstan       # Static analysis
composer bin-ecs           # Coding standards
composer bin-rector        # Code transformation

๐Ÿ“œ License

This bundle is licensed under the MIT license. See the LICENSE file for more details.

Developed by Juergen Schwind and other contributors.

๐Ÿค Contributing

Contributions are welcome! If you'd like to contribute, please fork the repository and submit a pull request with your changes or improvements. We're looking for contributions in the following areas:

  • Bug fixes
  • Feature enhancements
  • Documentation improvements

Before submitting your pull request, please ensure your changes are well-documented and follow the existing coding style of the project.

๐Ÿ“ซ Contact

If you have any questions, feature requests, or issues, please open an issue on our GitHub repository or submit a pull request.

Always up-to-date. Simple. Composer-native asset management.