PHPackages                             kriss/composer-assets-plugin - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. kriss/composer-assets-plugin

ActiveComposer-plugin[Utility &amp; Helpers](/categories/utility)

kriss/composer-assets-plugin
============================

Download assets(js/css/npm/github...) to project path

v2.0.0(4mo ago)1883MITPHPPHP &gt;=8.2CI passing

Since Nov 1Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/krissss/composer-assets-plugin)[ Packagist](https://packagist.org/packages/kriss/composer-assets-plugin)[ RSS](/packages/kriss-composer-assets-plugin/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

kriss/composer-assets-plugin
============================

[](#krisscomposer-assets-plugin)

[中文](./README_CN.md)

Purpose of the plugin:

Static resources (such as jquery, bootstrap, etc.) are required in PHP projects,

I don't want to use NPM (it may not be NodeJs in the online environment),

I don't want to download the corresponding resources from NPM or GitHub and put them back into the project (it will pollute the Git record, and there may be developers who may have changed such resources)

Logic: Using the Composer plugin, download resources to a folder in the project through the configured URL, and specify the extraction of partial files

Usage
-----

[](#usage)

### 1. Installation dependencies

[](#1-installation-dependencies)

```
composer require kriss/composer-assets-plugin
```

### 2. Configure the resources that need to be downloaded

[](#2-configure-the-resources-that-need-to-be-downloaded)

You can configure assets in two ways:

#### Method 1: Configure in composer.json (Traditional)

[](#method-1-configure-in-composerjson-traditional)

Configure 'composer. json' in the root directory of the project and add the following configuration (without comments):

```
{
  "extra": {
    "assets-dir": "public/assets", // Relative to the vendor directory
    "assets-pkgs": [ // array
      {
        // An example of any URL, from github (currently only supports resources of the. zip/. tar. gz/. tgz class)
        "url": "https://github.com/baidu/amis/releases/download/v2.2.0/sdk.tar.gz",
        "save_path": "amis@2.2.0", // 将保存到 public/assets/amis@2.2.0 下
      },
      {
        // Example of any URL, from NPM
        "url": "https://registry.npmjs.org/amis/-/amis-2.2.0.tgz",
        "save_path": "amis@2.2.0",
      },
      {
        // Example of NPM (recommended)
        "type": "npm",
        "name": "amis", // npm package name
        "version": "2.2.0",
        "only_files": [ // Specify which files are required. After the change, the downloaded directory needs to be deleted, otherwise it cannot be updated
          "sdk/thirds",
          "sdk/helper.css",
          "sdk/iconfont.css",
          "sdk/sdk.js"
        ],
        // "save_path": "amis/2.2.0", // Can override the default NPM save path address
      },
      {
        // Example of Github (using source code)
        "type": "github",
        "name": "baidu/amis", // github repo
        "version": "v2.2.0" // github tag
      }
    ]
  }
}
```

#### Method 2: Use External Config File (Recommended)

[](#method-2-use-external-config-file-recommended)

For better maintainability, you can use an external configuration file:

**Step 1:** Add `assets-config` to composer.json:

```
{
  "extra": {
    "assets-config": "assets.config.php" // or "assets.config.json"
  }
}
```

**Step 2:** Create the config file in your project root:

**Option A: PHP Config (assets.config.php)**

```
