kriss/composer-assets-plugin

将资源(如js/css/npm/github...)下载到项目路径

v1.0.0 2023-11-01 10:05 UTC

This package is auto-updated.

Last update: 2024-08-30 01:49:59 UTC


README

中文

插件目的

PHP项目中需要静态资源(如jquery、bootstrap等),

我不想使用NPM(可能在线环境中不是NodeJs),

我不想从NPM或GitHub下载相应的资源并将其放回项目中(这会污染Git记录,并且可能存在修改过这些资源的开发者)

逻辑:使用Composer插件,通过配置的URL将资源下载到项目的一个文件夹中,并指定提取部分文件

使用方法

1. 安装依赖

composer require kriss/composer-assets-plugin

2. 配置需要下载的资源

在项目的根目录下配置'composer.json'并添加以下配置(不带注释)

{
  "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
      }
    ]
  }
}

3. 执行下载

composer assets-download
# or
composer install # trigger from event