Laravel 4&巴塞特系列

时间:2013-07-16 09:58:04

标签: laravel assets

我的安装似乎很好,因为默认的“应用程序”集合可以正常工作。

但是我尝试创建一个新的集合,但我似乎无法获得正确的构建:

在我的global.php中(在文档中,它说它必须在config / packages等的某个地方,但我想这只适用于Laravel 3?)我提出以下内容:

    Basset::collection('preview', function($collection)
    {
        $collection->stylesheet('stylesheets/bootstrap.min.css');
        $collection->stylesheet('stylesheets/bootstrap-responsive.min.css');
        $collection->javascript('javascripts/bootstrap.min.js');
    });

所以我想,只需与工匠创建一个构建“预览”:

php artisan basset:build preview

输出:

[preview] Stylesheets build was not required for collection.
[preview] Javascripts build was not required for collection.

当我查看我的文件夹“builds”时,我只看到应用程序集合,没有添加了工作表/脚本的新文件夹“preview”。 使用@stylesheets('preview')在我的视图中加载它也没有做任何事情。

有什么建议可以让它发挥作用吗?谢谢!

3 个答案:

答案 0 :(得分:1)

你需要在Basset插件中选择的config / packages中添加一个文件 - 最简单的方法就是运行artisan config:publish jasonlewis/basset

然后,将您的集合添加到collections数组中,例如:

'preview' => function($collection) {
    $collection->stylesheet('stylesheets/bootstrap.min.css');
    $collection->stylesheet('stylesheets/bootstrap-responsive.min.css');
    $collection->javascript('javascripts/bootstrap.min.js');
},

docs确实暗示你可以这样做,但我还没弄明白 - 这个配置方法确实有效。

答案 1 :(得分:0)

使用php artisan config:publish jasonlewis/basset发布配置后,导航到app \ config \ packages \ jasonlewis \ basset并在那里编辑config.php。

然后,将您的集合添加到collections数组中,例如:

    'collections' => array(

    'application' => function($collection)
    {
        // Switch to the stylesheets directory and require the "less" and "sass" directories.
        // These directories both have a filter applied to them so that the built
        // collection will contain valid CSS.
        $directory = $collection->directory('assets/stylesheets', function($collection)
        {
            $collection->requireDirectory('less')->apply('Less');
            $collection->requireDirectory('sass')->apply('Sass');
            $collection->requireDirectory();
        });

        $directory->apply('CssMin');
        $directory->apply('UriRewriteFilter');

        // Switch to the javascripts directory and require the "coffeescript" directory. As
        // with the above directories we'll apply the CoffeeScript filter to the directory
        // so the built collection contains valid JS.
        $directory = $collection->directory('assets/javascripts', function($collection)
        {
            $collection->requireDirectory('coffeescripts')->apply('CoffeeScript');
            $collection->requireDirectory();
        });

        $directory->apply('JsMin');
    },

    'login' => function($collection)
    {

        $directory = $collection->directory('assets/stylesheets', function($collection)
        {
            $collection->stylesheet('bootstrap.min.css');
            $collection->stylesheet('metro.css');
            $collection->stylesheet('font-awesome.css');
            $collection->stylesheet('style.css');
            $collection->stylesheet('style_responsive.css');
            $collection->stylesheet('style_default.css');
            $collection->stylesheet('uniform.default.css');
        });

        $directory->apply('CssMin');
        $directory->apply('UriRewriteFilter');

        $directory = $collection->directory('assets/javascripts', function($collection)
        {
            $collection->javascript('jquery-1.8.3.min.js');
            $collection->javascript('bootstrap.min.js');
            $collection->javascript('jquery.uniform.min.js');
            $collection->javascript('jquery.blockui.js');
            $collection->javascript('jquery.validate.min.js');
            $collection->javascript('app.js');
        });

        $directory->apply('JsMin');            

    }

),

答案 2 :(得分:0)

试试这个/

'collections' => array(

'application' => function($collection)
{
    // Switch to the stylesheets directory and require the "less" and "sass" directories.
    // These directories both have a filter applied to them so that the built
    // collection will contain valid CSS.
    $directory = $collection->directory('assets/stylesheets', function($collection)
    {
        $collection->requireTree();

    });

    $directory->apply('CssMin');
    $directory->apply('UriRewriteFilter');

    // Switch to the javascripts directory and require the "coffeescript" directory. As
    // with the above directories we'll apply the CoffeeScript filter to the directory
    // so the built collection contains valid JS.
    $directory = $collection->directory('assets/javascripts', function($collection)
    {
        $collection->requireDirectory();
        $collection->javascript('//ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js');
    });
}