kloy/assetix 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

kloy/assetix

Composer 安装命令:

composer require kloy/assetix

包简介

Boilerplate for quickly taking advantage of Assetic asset management.

README 文档

README

A simple wrapper for easily using Assetic. Provides a simple way for including assets and letting Assetic build and cache them in production.

Assetix uses composer for including Assetic. Follow the steps at Packagist if you are unfamiliar with composer to get going.

Example

require_once('classes/assetix.php');

use Assetix\Assetix;

// Instantiate Assetix
$assetix = new Assetix();

// Add css files to group base_css
$css = array('/css/test.css');
$assetix->css('base_css', $css);

// Add js files to group base_js
$js = array('/js/underscore.js', '/js/*');
$assetix->js('base_js', $js);

// Echo out raw compiled files
echo $assetix->css('base_css', true)."\n";
echo $assetix->js('base_js', true)."\n";

// Echo out links to compiled files
echo $assetix->css('base_css')."\n";
echo $assetix->js('base_js')."\n";

Installation

Follow the instructions on Packagist to add "kloy/assetix": "0.1.*" in the require section of your composer.json file and install. Once installed run npm install . from the vendor/kloy/assetix/ dir. This will install the needed nodejs modules for compiling less, stylus, and coffeescript.

Available asset function

Assetix features the ability to compile many assets. All functions implement the same argument structure. This structure is func('group', array() /* asset paths */, bool /* true for raw outputting, false for a link */). As you may have noticed, you can call func() without an array of assets if you just wish to get a link from a previously defined group. You may call it with a second argument of true to get the raw output of the group. The current list of asset functions is below...

  • css() - normal css stylesheet
  • less() - less css
  • styl() - stylus css
  • js() - normal javascript
  • coffee() - coffee-script
  • underscore() - underscore javascript templates
  • handlebars() - handlebars javascript templates

How does the build process work?

The assets are lazily built on the first request for them. Once built they are cached so further builds for the same asset is not needed. In a production setting you will assign a version number in the assetix config. When this version number is changed all assets are rebuilt and a new file with this version number is generated for cache busting purposes.

Assets that become css are first compiled to css, then images are embedded into the css via datauri and base64 encoding, last the assets get minimized. Assets that become js are compiled to js and minimized.

Internet Explorer Version 7 and below.

IE 7 and below does not support datauri functionality used for embedding images into css. In order to work around this you can prefix 'ie_' to a group's name. Here is an example.

css('ie_foo', array('css/*'));

This will cause the compiler to not use the embedcss filter which means all images will be requested as normal.

Rewriting CSS

By the default all relative ../ paths are replaced with /assets/production/. To modify this behavior change $config['css_rewrite_replacement'] to use a different replacement value or $config['css_rewrite_pattern'] to use a different pattern for matching.The way the css rewrite works is the content of a css file is passed through preg_replace. So make sure your values for $config['css_rewrite_replacement'] and $config['css_rewrite_pattern'] work properly with this function.

To modify the css rewrite on the fly you can call $assetix->set_rewrite($replacement, $pattern);

Example:

$assetix->set_rewrite('\\1/foo/');
$test2 = $assetix->css('ie_base_css', array('/rewrite_css/test.2.css'), true);

All calls to $assetix->css will use the set replacement value for now on. To change the replacement value again just call $assetix->set_rewrite() with new values.

To better understand how css rewrite works take a look at Assetix::_construct() and Assetix::set_rewrite() and follow the code back to MyCssRewriteFilter.

API

The public available APIs are described in interfaces. Currently the iAssetix and iCompiler interfaces exist. This project follows Semantic Versioning.

kloy/assetix 适用场景与选型建议

kloy/assetix 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 51 次下载、GitHub Stars 达 4, 最近一次更新时间为 2012 年 03 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「assets」 「compression」 「minification」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kloy/assetix 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kloy/assetix 我们能提供哪些服务?
定制开发 / 二次开发

基于 kloy/assetix 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2012-03-19