lightgear/asset 问题修复 & 功能扩展

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

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

lightgear/asset

Composer 安装命令:

composer require lightgear/asset

包简介

Easy asset Management for Laravel 4

README 文档

README

This project has been discountinued since there are better way to handle assets nowadays.
I switched to Gulp.js and will not get back.
This repository will be kept in case somebody uses it in production.

Simple and effective assets management for Laravel 4

Overview

The Lightgear/Asset package is meant to simplify the creation and maintenance of the essential assets of a Laravel 4 based application.

Features

  • Supported asset types: "less", "css"" and "javascript" files. I do NOT plan to add support for other types like Coffeescript simply because I want to keep the package footprint as small as possible.
  • Combining and minifying (any combination of the two) are fully supported
  • Simple but effective caching support is provided. This avoids generation of the assets on every request. Caching needs to be turned on in the config (since you probably only want to do this on production).
  • Asset groups

Installation

Via Laravel 4 Package Installer

php artisan package:install lightgear/asset

Manual

Just require

"lightgear/asset": "1.1"

in your composer.json and run

composer update

Then register the service provider

'Lightgear\Asset\AssetServiceProvider'

and, optionally, the alias

'Asset' => 'Lightgear\Asset\Facades\Asset'

in app/config/app.php

Publish configuration with

php artisan config:publish lightgear/asset

This will ceate the app/config/packages/lightgear/asset/config.php file.

Finally create the directory specified as "public_dir" in the config file and give it full writing permissions.

Usage

All you need to do is register your assets with either registerStyles() or registerScripts() methods. Important: assets need to be registered in a file which is always loaded (ex. in a package's ServiceProvider). For example, to register a package assets you would use something like this in your service provider:

/**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $styles = array(
            'src/assets/styles',
            'src/assets/pure/pure/pure-min.css'
        );

        $asset = $this->app->make('asset');

        // register styles of a vendor package and assign them
        // to the default "general" group
        $asset->registerStyles($styles, 'vendor/package');

        // register styles of a vendor package and assign them
        // to the "frontend" group
        $asset->registerStyles($styles, 'vendor/package', 'frontend');

        // the same goes with scripts for whom you would use for example
        $asset->registerScripts(array('src/scripts')), 'vendor/package');
    }

or you could register assets located in app/assets with

Asset::registerStyles(array(
        'css/shared.less'
    )
);
or
Asset::registerScripts(array(
        'js/shared.js'
    )
);

As you notice in the examples both files and directories can be registered. It's worth noticing that directories are added recursively.

Configuration

A number of config options allow you to customize the handling of the assets. Please check src/config/config.php for details.

Templating

The assets can be printed out in a (blade) template by using

// prints all the registered styles
{{ Asset::styles() }}

// prints only the "frontend" group
{{ Asset::styles('frontend') }}

// prints the "frontend" and "mygroup" groups
{{ Asset::styles(array('frontend', 'mygroup')) }}

and the same syntax is used for the scripts

{{ Asset::scripts() }}

Artisan commands

The package comes with 2 commands:

php artisan asset:clean

which deletes all published and cached assets and

php artisan asset:generate

which generates and publishes the registered assets

Permissions

If you experience permissions issues when running the above commands, it's because the user running artisan is different from the one that generates the assets through the webserver (www-data for example). The issue is explained in greater details at http://symfony.com/doc/current/book/installation.html#configuration-and-setup To fix the issue it's enough to follow the steps outlined in this page. For example on Ubuntu I run the following commands from the project root

sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX public/assets
sudo setfacl -dR -m u:www-data:rwX -m u:`whoami`:rwX public/assets

When using caching, you would need to do the same

sudo setfacl -R -m u:www-data:rwX -m u:`whoami`:rwX app/storage
sudo setfacl -dR -m u:www-data:rwX -m u:`whoami`:rwX app/storage

Changelog

1.1: Laravel 4.1 compatibility
1.0: add support for asset groups and improve cache handling
0.8: initial release

lightgear/asset 适用场景与选型建议

lightgear/asset 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.99k 次下载、GitHub Stars 达 24, 最近一次更新时间为 2013 年 10 月 18 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 1.99k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 24
  • 点击次数: 9
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 24
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-10-18