Skip to content

Composer plugin that installs dependencies and compiles assets based on configuration.

License

Notifications You must be signed in to change notification settings

inpsyde/composer-asset-compiler

Repository files navigation

Composer Asset Compiler

PHP Static Analysis PHP Unit Tests


What is this

A Composer plugin that automatically "compiles" frontend assets (js, css, etc.) for packages installed via Composer.

A quick example

Let's assume we have a website project having a composer.json that looks like this:

{
    "name": "acme/my-project",
    "require": {
        "acme/foo": "^1",
        "acme/bar": "^2",
        "inpsyde/composer-assets-compiler": "^3"
    },
    "extra": {
        "composer-asset-compiler": { "auto-run": true }
    }
}

And then suppose that acme/foo's composer.json looks like this:

{
    "name": "acme/foo",
    "extra": {
        "composer-asset-compiler": "gulp"
    }
}

and acme/bar's composer.json looks like this:

{
    "name": "acme/bar",
    "extra": {
        "composer-asset-compiler": "build"
    }
}

When we'll install the project with Composer, the following happens:

  1. Composer installs the three required packages
  2. Immediately after that, the plugin executes and:
    1. the plugin looks for all installed packages (including transitive dependencies) that have a composer-asset-compiler configuration, finding "acme/foo"and "acme/bar"
    2. moves to "acme/foo" installation folder, and executes npm install && npm run gulp
    3. moves to "acme/bar" installation folder, and executes npm install && npm run build

At the end of the process, we have a project with the dependencies installed, and their assets processed.

The example above is the simplest use case, but the plugin has many possible configurations and advanced use cases.

Documentation

Copyright and License

Good news, this library is free for everyone! Since it's released under the MIT License you can use it free of charge on your personal or commercial website.