markstory/mini-asset
Composer 安装命令:
composer require markstory/mini-asset
包简介
An asset compression library. Provides file concatenation and a flexible filter system for preprocessing and minification.
README 文档
README
Mini Asset is a small footprint library that provide tools to assist in building an asset minification/optimization pipeline. It uses a simple INI based configuration file that lets you define output files, that are comprised of a number of input files. Input files can be processed by filters on a per-extension or per file basis. Filters allow you to integrate existing pre-processors and minifiers or build your own.
Features
- Built-in support for LESScss, Sass and CoffeeScript, as well as several minifiers.
- Powerful and flexible filter system allowing you to add your own minifiers/pre-processors.
- Simple ini configuration files.
- Incremental builds that don't recompile assets when they don't need to be.
- Command Line Tools for building and clearing assets.
Installing
Add this library to your application with composer, after that you can start integrating MiniAsset into your application and use the provided CLI tools to generate asset targets:
php composer.phar require 'markstory/mini-asset'
Usage
Before MiniAsset can do anything, you'll need to define a configuration file to define your asset and which filters apply to them. For example purposes, we'll assume you have some CSS files that need to be minified.
Defining a configuration file
In your application's configuration directory create a file called
assets.ini. In this file we'll put all the configuration that MiniAsset
needs. We'll cover how to use multiple configuration files later on. Assuming your,
application has a app.css and reset.css put the following in your config file:
[css] cachePath = WEBROOT/cache_css/ paths[] = WEBROOT/css/* filters[] = SimpleCssMin [app.css] files[] = reset.css files[] = app.css
The above also assumes that WEBROOT resolves to your application's document
root. In the above we defined a few sections. First, the [css] section defines how all
CSS files should behave:
- The
cachePathoption tells MiniAsset where to store generated assets. - The
paths[]options tell MiniAsset where to find CSS files. Paths use glob syntax. - The
filters[]options let you configure which filters are applied to all CSS files. Filters are applied in the order they are defined. See the filters documentation for the available filters and their options.
We also defined an [app.css] section. This section defines the files that are used to
create WEBROOT/cache_css/app.css when it is generated. We've added two files.
See the sample configuration file for an annotated sample configuration file, and configuration docs for more configuration reference.
Use the CLI tool to build your asset
With a build target defined, we can now generate our asset. We can use the CLI tool to generate our assets:
vendor/bin/mini_asset build --config /path/to/assets.ini
The above should generate output indicating that the all.css file we defined
was compiled. If we were to re-run the above command all.css would be skipped.
MiniAsset is smart enough to know when the components of a build target change and
only re-build files when it is necessary.
You can also use the mini_asset CLI tool to clear targets:
vendor/bin/mini_asset clear --config /path/to/assets.ini
PSR7 Middleware
Mini-asset provides a PSR7 middleware adapter that implements the pattern found in zendframework/zend-stratagility and SlimPHP. Before you can use the middleware provided by mini-asset be sure to setup a config file with your assets. Next, integrate mini-asset into your middleware stack. For example in a SlimPHP app you would do:
use MiniAsset\AssetConfig; use MiniAsset\Middleware\AssetMiddleware; $assetConfig = AssetConfig::buildFromIniFile(__DIR__ . '../config/assets.ini'); $assets = new AssetMiddleware($assetConfig); $app->add($assets);
Framework Integrations
- CakePHP - AssetCompress plugin.
Issues
Please report any issues you have with the plugin to the issue tracker on github.
License
Mini Asset is offered under an MIT license.
Copyright
2010-2026 Mark Story (http://mark-story.com)
Authors
See the github contributors list.
Changelog
See CHANGELOG for changes only available on master. See
github releases for changelogs on previous releases.
markstory/mini-asset 适用场景与选型建议
markstory/mini-asset 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 786.78k 次下载、GitHub Stars 达 63, 最近一次更新时间为 2015 年 04 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「assets」 「cakephp」 「sass」 「less」 「minifier」 「coffee-script」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 markstory/mini-asset 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 markstory/mini-asset 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 markstory/mini-asset 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
CakePHP 4.x AdminLTE Theme.
Asset Management for PHP
Caching and compression for Twig assets (JavaScript and CSS).
Email Toolkit Plugin for CakePHP
Tool for loading or deploying CSS and JS files into web pages
Rhino, a CMS and Application-Framework plugin for CakePHP
统计信息
- 总下载量: 786.78k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 66
- 点击次数: 38
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-04-12