simple-php/composer-assets-plugin

用于安装资产的Composer插件。

安装: 7

依赖者: 1

建议者: 0

安全性: 0

星星: 0

观察者: 1

分支: 5

类型:composer-plugin

1.0 2020-02-28 07:43 UTC

This package is auto-updated.

Last update: 2024-09-28 19:42:11 UTC


README

用于安装资产的Composer插件。

Become a Patron!

安装

使用 Composer

composer require simple-php/composer-assets-plugin

库需要PHP 5.4.0或更高版本。

命令

  • composer refresh-assets - 刷新 assets 目录中的文件

资产配置

  • assets-filesextra 部分
    • true - 创建整个包目录的符号链接
    • 文件路径 - 创建单个文件或目录的符号链接
    • 文件路径列表 - 创建文件/目录的符号链接

示例

{
	"extra": {
		"assets-files": [
			"static/plugin.js",
			"static/plugin.css",
			"static/icons.png"
		]
	}
}
  • static/plugin.js - 将文件链接到 assets/org/package/plugin.js
  • static/plugin.css - 将文件链接到 assets/org/package/plugin.css
  • static/icons.png - 将文件链接到 assets/org/package/icons.png

默认情况下,资产文件存储在根包composer配置中指定的 assets-dir。包名用作路径,例如,对于包 package-owner/package-name,默认将使用以下路径:assets-dir/package-owner/package-name。您可以在 extra 部分中指定包的不同默认路径 assets-target

  • assets-target 复制资产文件的目标路径,可选
    • 如果指定了相对路径,它将相对于 assets-dir
    • 如果指定了绝对路径,它将相对于 vendor-dir 的父目录

示例

{
    "extra": {
        "assets-target": "package1",
        "assets-files": [
               ... some assets files ...
        ]
    }
}

Relative path specified, assets files will be copied to `assets-dir`/package1

``` json
{
    "extra": {
        "assets-target": "/templates/default/js",
        "assets-files": [
               ... some assets files ...
        ]
    }
}

Absolute path specified, assets files will be copied to `project-dir`/templates/default/js, where `project-dir` is parent directory of composer `vendor-dir`
IMPORTANT: Assets files will not be cleaned on package update or removing, if default absolute path for `assets-target` is used. 
If you need automatic cleanup of assets files for this package you must redefine `assets-target` for this package in root package config.

### Root package

* `assets-dir` - directory for installing of assets, default `assets`, relative to `vendor-dir`
* `assets-directory` - alias for `assets-dir`
* `assets-files` - list of asset files in incompatible packages, it overrides `assets-files` from installed packages
* `assets-strategy` - install strategy for assets
	* `auto` - select strategy by platform (default value)
	* `copy` - copy all assets, default strategy on Windows
	* `symlink` - create relative symlinks, default strategy on non-Windows platforms
* `assets-target` - target directory for specific packages, relative to `vendor-dir`, must be out of `assets-dir`

Example:

``` json
{
	"config": {
		"assets-dir": "public",
		"assets-files": {
			"org/package": true,
			"org/package2": "js/calendar.js",
			"org/package3": [
				"static/plugin.js",
				"static/plugin.css",
				"static/icons.png"
			]
		},
		"assets-target": {
			"ckeditor/ckeditor": "admin/wysiwyg"
		}
	}
}
  • org/package - 将整个包目录链接到 public/org/package
  • org/package2 - 将文件 js/calendar.js 链接到 public/org/package2/calendar.js
  • org/package3
    • static/plugin.js - 将文件链接到 public/org/package3/plugin.js
    • static/plugin.css - 将文件链接到 public/org/package3/plugin.css
    • static/icons.png - 将文件链接到 public/org/package3/icons.png
  • ckeditor/ckeditor - 将文件链接到 admin/wysiwyg

默认映射

插件为所选不兼容的包提供默认映射。您可以在您的 composer.json 中覆盖此映射。

具有默认映射的包列表

  • ckeditor/ckeditor
  • components/jquery
  • nette/forms
  • o5/grido

在哪里找到支持的包?

一些库和包默认支持Composer。对于其他存在shim-repositories

您始终可以在 Packagist 上搜索包。

许可证: 新BSD许可证
作者:Jan Pecha, https://www.janpecha.cz/