2

I have the following task:

var inject = require('gulp-inject');
...
gulp.task('index-build', function () {
    return gulp.src(config.index)
        .pipe(
            inject(gulp.src(config.build + '/vendor/**/*.js', { read: false }))
        )
        .pipe(gulp.dest(config.build));
});

Mostly this does what it's supposed to: concatenate files in alphabetic order within the paths, resulting in something like:

    ...
    <script src="/vendor/angular/angular.js"></script>
    <script src="/vendor/angular-resource/angular-resource.js"></script>
    ...

but sometimes, irregularly, it does this:

    ...
    <script src="/vendor/angular-resource/angular-resource.js"></script>
    <script src="/vendor/angular/angular.js"></script>
    ...

Which breaks the app since angular-resource.js depends on angular.js.

Why does gulp do this unpredictably and how do I assure that the order is the same each time?

maxjvh
  • 214
  • 1
  • 6
  • 18
  • what dont you use gulp-wiredep, which will make sure to load modules as per dependencies – harishr May 27 '15 at 04:59
  • if you cant use gulp-wiredep then the only way would be specify files one by one in sequence you want them to be – harishr May 27 '15 at 05:00
  • But why doesn't gulp process the files in alphabetic order? – maxjvh May 27 '15 at 11:02
  • use gulp-sort if you want to process files in alphabetical order. but i dont think alphabetic sort will help. your problem mostly would be better solved [like this](http://stackoverflow.com/questions/21961142/gulp-concat-scripts-in-order) – harishr May 27 '15 at 11:57
  • I could, but seems kind of stupid to use a plugin just to make the ordering static. Why does it change from time to time? – maxjvh Jun 01 '15 at 06:48
  • its not problem with the plugins... its mostly on the basis of how operating systems provides it the list of files in a given directory, which no one can predict.. – harishr Jun 01 '15 at 08:19

1 Answers1

2

use gulp-sort to get the file in alphabetical sequence.

The plugins do output the files in the sequence in which they receive it, hence the sequence of files is even out of their control.

and its actually good that they dont sort the files, the plugin should only do what it is supposed to do and add nothing extra.

harishr
  • 17,807
  • 9
  • 78
  • 125