slushie/laravel-assetic
Composer 安装命令:
composer require slushie/laravel-assetic
包简介
Assetic support for Laravel 4
README 文档
README
Easily integrate Assetic with Laravel 4.
Key Features
- Easily maintain assets within groups.
- Instant single file compilation, concatenation, and minification.
- Apply multiple filters to each group.
- Automatically updates output files when their inputs have been changed.
- Pre-compile assets using
artisan asset:warm.
Usage
Add to your composer.json:
"require": { "laravel/framework": "4.0.*", "slushie/laravel-assetic": "dev-master", "lmammino/jsmin4assetic": "1.0.0", "leafo/lessphp": "0.4.0" }
After running composer update, you need to add the service provider (and optionally, alias the Asset facade) in your app/config/app.php file:
'providers' => array( ... 'Slushie\LaravelAssetic\LaravelAsseticServiceProvider', ... ), 'aliases' => array( ... 'Asset' => 'Slushie\LaravelAssetic\Facades\AssetFacade', ... ),
Once your app's configuration has been updated, generate the package config:
php artisan config:publish slushie/laravel-assetic
Now the laravel-assetic configuration file will be available at:
app/config/packages/slushie/laravel-assetic/config.php
Finally, edit the configuration file file to define your assets. You can define multiple groups, each with different filters and assets.
Defining Filters
Filters are defined within the package configuration file.
'filters' => array( 'css_min' => 'Assetic\Filter\CssMinFilter', 'css_import' => 'Assetic\Filter\CssImportFilter', 'css_rewrite' => 'Assetic\Filter\CssRewriteFilter', 'embed_css' => 'Assetic\Filter\PhpCssEmbedFilter', 'less_php' => 'Assetic\Filter\LessphpFilter', 'js_min' => 'Assetic\Filter\JSMinFilter', 'coffee_script' => 'Assetic\Filter\CoffeeScriptFilter', 'yui_js' => function () { return new Assetic\Filter\Yui\JsCompressorFilter('yui-compressor.jar'); }, ),
Adding Assets to Groups
Each group defines assets and filters as inputs, and an output file that should be included in your view.
'groups' => array( 'main_js' => array( 'filters' => array( 'js_min', ), 'assets' => array( 'jquery', // Named asset defined below 'assets/js/common/search.js', // Single file 'assets/js/coolarize/*js', // Folder inclusion ), 'output' => 'scripts.js', // Writable output relative to public_path() ), ),
Using Assets in Views
Once defined, your groups can then be accessed from within your views using the Asset facade.
To link to the main_js group, you can use the Asset::url() method as follows:
<script src="<?php echo Asset::url('main_js'); ?>"></script>
This will output the URL to the asset file (in this example, /scripts.js).
When the page loaded, Assetic will generate the file, joining all files and running the defined filters.
You can also generate the asset output files via the artisan command:
php artisan asset:warm
Of course, this can be performed as a composer post-install command to generate assets at deployment time.
More Information
More information can be acquired by reading through the source, which is fully documented, or you may feel free to raise issues at https://github.com/slushie/laravel-assetic/issues
slushie/laravel-assetic 适用场景与选型建议
slushie/laravel-assetic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 16.97k 次下载、GitHub Stars 达 37, 最近一次更新时间为 2013 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 slushie/laravel-assetic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 slushie/laravel-assetic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 16.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 38
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2013-10-18