easybib / asset-php
作为 composer 脚本,在文件名前添加内容 MD5。
2.0.1
2015-02-27 14:00 UTC
This package is not auto-updated.
Last update: 2024-09-14 16:03:18 UTC
README
作为 composer 脚本,在文件名前添加内容 MD5。
做了
- 将任何您想要复制的文件复制到
[content-md5]-original-file-name.ext
文件 - 将此文件名提供给您的应用程序
不做
- 对您的文件进行任何其他操作(无压缩,无其他操作)
设置/使用
$ composer require easybib/asset-php 1.\*
composer
脚本公开了两个 composer "脚本" - EasyBib\\Asset::run
和 EasyBib\\Asset::clear
。您还需要将配置添加到您的 composer.json
文件中。
例如
"config": { "asset": { "/js/main.js": {"from": "frontend/src", "to": "frontend/dist"}, "/css/main.css": {"from": "web/css", "to": "web/css"} } }, "scripts": { "build": "EasyBib\\Asset::run" },
config.asset
语法如下
"the name you call Asset::path() with" => {from: "source directory", to: "target directory"}
当然,您可以选择其他脚本名称。Composer 也有一些魔法脚本名称,它会在自动触发。
app
在您的应用程序中,将文件的路径替换为对 EasyBib\Asset::path
的调用。
例如,在上面的配置中,以下内容
<script src="<?php EasyBib\\Asset::path('/js/main.js'); ?>"></script>
将在您运行 composer build
后展开
<script src="/js/123abcdwhatever-main.js"></script>
。
要使其回退到源文件,您可以运行 EasyBib\Asset::clear()
。但由于 PHP 中的 APC 的工作方式,您必须在该应用程序内(或至少使用相同的 SAPI)运行该命令。