jasonlewis / basset

A better asset management package for Laravel.
http://jasonlewis.me/code/basset
240 stars 76 forks source link

requireDirectory() strangely sorts files #187

Closed sukazavr closed 6 years ago

sukazavr commented 11 years ago
'public' => function($collection)
{
    $collection->directory('../app/assets/scripts', function($collection)
    {
        $collection->add('angular.min.js');
        $collection->requireDirectory('app');
    })->apply('JsMin');
}

In app folder:

app.js
controllers.js
directives.js
factories.js
filters.js

On local environment everything good, but on production environment i get strangely sort, like this:

filters.js
app.js
controllers.js
directives.js
factories.js

Why filters.js is the first file?

fedeisas commented 11 years ago

@sukazavr I don't really know how Basset do asset ordering.

Since Basset doesn't really provides any method to handle dependencies, you shouldn't rely on alphabetic ordering to solve your Angular dependencies. I also use Angular and Basset and this is how I solve that:

$collection->javascript('app.js');
$collection->requireDirectory('app/templates');
$collection->requireDirectory('app/directives');
$collection->requireDirectory('app/services');
$collection->requireDirectory('app/filters');
$collection->requireDirectory('app/controllers');

I have a javascripts folder with several subfolders for filters, controllers, templates, etc. In the root there's an app.js file which generates the Angular app:

// app.js
var app = angular.module('myApp', []);

Then each controller, service, filter just extends from that app variable.

That way I don't have to worry which file is concatenated first, as long as my app.js is always on top of it.

Hope it helps.