承接 kriss/composer-assets-plugin 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kriss/composer-assets-plugin

最新稳定版本:v2.0.0

Composer 安装命令:

composer require kriss/composer-assets-plugin

包简介

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

README 文档

README

中文

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

1. Installation dependencies

composer require kriss/composer-assets-plugin

2. Configure the resources that need to be downloaded

You can configure assets in two ways:

Method 1: Configure in composer.json (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)

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)

<?php

return [
    'assets-dir' => 'public/assets',
    'assets-pkgs' => [
        [
            'type' => 'npm',
            'name' => 'vue',
            'version' => '3.4.0',
            'save-path' => 'vue',
            'only-files' => ['dist/vue.global.js'],
        ],
        [
            'type' => 'github',
            'name' => 'twbs/bootstrap',
            'version' => 'v5.3.2',
            'save-path' => 'bootstrap',
        ],
    ],
];

Option B: JSON Config (assets.config.json)

{
  "assets-dir": "public/assets",
  "assets-pkgs": [
    {
      "type": "npm",
      "name": "vue",
      "version": "3.4.0",
      "save-path": "vue",
      "only-files": ["dist/vue.global.js"]
    }
  ]
}

Note: You can use both assets_dir (snake_case) or assets-dir (kebab-case) in config files.

3. Execute Download

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

统计信息

  • 总下载量: 925
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-11-01