userfrosting/assets
最新稳定版本:6.2.0
Composer 安装命令:
composer require userfrosting/assets
包简介
Assets module for UserFrosting
README 文档
README
| Branch | Build | Coverage | Style |
|---|---|---|---|
| master | |||
| develop | |
Assets is a library originally created for UserFrosting 4 to make it much easier to reference frontend assets in both production and development contexts.
Out of the box it can:
- Provide an easy way to generate an absolute url to an asset via a locator.
- Provide a basic level of integration with
gulp-bundle-assetsand complete integration with@userfrosting/gulp-bundle-assets, making it easy to reference asset bundles. - Integrate via a common interface with virtually any bundling system.
- Integrate with Slim to serve assets that are inaccessible from the public folder, in the development context.
- Perform url-to-path transformations. Useful for making debuggable URLs that can be reverted back to the path to be used by the Slim asset server.
- Integrate with your preferred (and extendable) templating engine to provide easy access to asset bundles (that get wrapped with the appropriate tags) and individual assets.
Installation
composer require userfrosting/assets
Usage
To use Assets, you will need:
- An instance of
ResourceLocator, where you can add your desired search paths. - The locator scheme (if it exists) you wish to look for assets in.
- The base url (used in generating URLs to assets).
- The base path (used in trimming the absolute path returned by the locator).
<?php use UserFrosting\UniformResourceLocator\ResourceLocator; use UserFrosting\Assets\Assets; $basePath = __DIR__; $baseUrl = 'https://assets.userfrosting.com/'; $locator = new ResourceLocator($basePath); $locator->registerStream('assets', '', [ 'owls/assets', 'hawks/assets' ]); $assets = new Assets($locator, 'assets', $baseUrl);
Optionally 1 more argument can be passed into the
Assetsconstructor, an instance ofPrefixTransformer.Have a look at UserFrosting in dev mode to see this in action!
Asset Bundles
To access asset bundles from an Assets instance, it must first be passed an instance of AssetBundlesInterface via addAssetBundles. The following example demonstates how to integrate with @userfrosting/gulp-bundle-assets (and by extension gulp-bundle-assets). Note that raw bundles are only supported when their configuration is defined as JSON.
Directory Tree
/ ├build/ │ └asset-bundles.json └public/ └index.php
build/asset-bundles.json
{
"bundle": {
"js/main": {
"scripts": [
"js/bootstrap-3.3.1.js",
"js/crud.js"
]
},
"css/main": {
"styles": [
"vendor/font-awesome-4.5.0/css/font-awesome.css",
"css/bootstrap-3.3.1.css",
"css/bootstrap-custom.css",
"css/paper.css"
]
}
}
}
public/index.php
use UserFrosting\Assets\GulpBundleAssetsRawBundles; // Load asset bundles. $assetBundles = new GulpBundleAssetsRawBundles('../build/asset-bundles.json'); // Send loaded asset bundles to Assets instance. $assets->addAssetBundles($assetBundles); // Grab an asset bundle. $assets->getJsBundleAssets('js/main'); // Outputs ["js/bootstrap-3.3.1.js", "js/crud.js"]
Compiled bundles can be used in much the same way, except using GulpBundleAssetsCompiledBundles and the bundlers result file.
If using the original gulp-bundle-assets you'll need to include an additional setting options->result->type->styles/scripts="plain" in each bundle.
The Template Plugin
The template plugin is easy initialized by giving it the Assets instance, and simply gets passed into the templating engine environment of your choice to be used.
use UserFrosting\Assets\AssetsTemplatePlugin; $assetsPlugin = new AssetsTemplatePlugin($assets); // Some code that passes it to Twig rendering environment.
{# Gets replaced at runtime with the following. Additional argument is optional. #} {{ assets.js("js/main", { defer: true }) }}
<script src="https://assets.userfrosting.com/assets/bootstrap/js/bootstrap.js" defer="true"></script> <script src="https://assets.userfrosting.com/assets/bootstrap/js/npm.js" defer="true"></script>
Style Guide
Testing
userfrosting/assets 适用场景与选型建议
userfrosting/assets 是一款 基于 CSS 开发的 Composer 扩展包,目前已累计 46.95k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2016 年 04 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「assets」 「javascript」 「css」 「images」 「userfrosting」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 userfrosting/assets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 userfrosting/assets 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 userfrosting/assets 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Generates a Blade directive exporting all of your named Laravel routes. Also provides a nice route() helper function in JavaScript.
Asset Management for PHP
A Twig extension to insert css as inline styles with a tag
Caching and compression for Twig assets (JavaScript and CSS).
A pretty nice way to expose your translation messages to your JavaScript.
PHP client for the Google Closure Compiler API in one file.
统计信息
- 总下载量: 46.95k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-04-05