What gulp-angular-filesort really does for gulp-inject?

Viewed 2877

Can anybody show an example of what gulp-angular-filesort really does and how to use it properly?

The thing is that I’ve recently realized that my gulp-angular-filesort doesn’t sort angularjs files at all, however my AngularJS App with lots of files works fine. So, I’ve come up with two questions:

  1. Is AngualarJs still sensitive for source files order? As to me, it looks like it isn’t.
  2. What gulp-angular-filesort actually does? I can’t see any results of its work.

I’ve thought that gulp-angular-filesort looks at angular.module statements and sort files according to specified dependency in the brackets. It looks like I was wrong.

Please look at my sample below.

// File: Gulpfile.js

'use strict';

var
    gulp = require('gulp'),
    connect = require('gulp-connect'),
    angularFilesort = require('gulp-angular-filesort'),
    inject = require('gulp-inject');


gulp.task('default', function () {

    gulp.src('app/index.html')
        .pipe(inject(
            gulp.src(['app/js/**/*.js']).pipe(angularFilesort()),
            {
                addRootSlash: false,
                ignorePath: 'app'
            }
        ))
        .pipe(gulp.dest('app'))
    ;

    connect.server({
        root: 'app',
        port: 8081,
        livereload: true
    });

});

//a_services.js

'use strict';

angular.module('myServices', [])
    .factory('MyService', function () {
        return {
            myVar:1
        };
    })
;

//b_controllers.js

'use strict';

angular.module('myControllers', ['myServices'])
    .controller('MyController', function ($scope, MyService) {
        $scope.myVar = MyService.myVar;
    })
;

// c_app.js

'use strict';

angular.module('myApp', ['myControllers']);

The result of gulp-inject is the following:

<!-- inject:js -->
<script src="js/c_app.js"></script>
<script src="js/b_controllers.js"></script>
<script src="js/a_services.js"></script>
<!-- endinject -->

I was expected exactly an opposite order to make the App work (however it still does work). So, using of gulp-angular-filesort simply sorted files alphabetically, despite of all the dependencies specified in the angular.module(...,[...])

What is going on here?

2 Answers
Related