最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - gulp-order : not Ordering properly - Stack Overflow

programmeradmin6浏览0评论

Gulp newbie here, I downloaded gulp-order for ordering js files when concating *.js because some of my javascript files require jquery to load first.

Below are my gulpfile.js that have order,concat,rename & uglify.

var date = new Date();
var uniq = date.getTime();

gulp.task('admin-scripts', function() {
    return gulp.src(['assets/admin/js/*.js','!assets/admin/js/respond.min.js','!assets/admin/js/html5shiv.js'])
        .pipe(order([
            "assets/admin/js/jquery.min.js",
            'assets/admin/js/*.js'
        ]))
        .pipe(concat(uniq+'admin.js'))
        .pipe(gulp.dest('build/assets/admin/js/'))
        .pipe(rename(uniq+'admin.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('build/assets/admin/js/'));
});

But seems the ordering is not working.

the ordering is base on alphabet a.js > z.js instead of jquery.min.js > a.js > z.js

is there anything I'd code wrongly on the gulpfile.js?

Gulp newbie here, I downloaded gulp-order for ordering js files when concating *.js because some of my javascript files require jquery to load first.

Below are my gulpfile.js that have order,concat,rename & uglify.

var date = new Date();
var uniq = date.getTime();

gulp.task('admin-scripts', function() {
    return gulp.src(['assets/admin/js/*.js','!assets/admin/js/respond.min.js','!assets/admin/js/html5shiv.js'])
        .pipe(order([
            "assets/admin/js/jquery.min.js",
            'assets/admin/js/*.js'
        ]))
        .pipe(concat(uniq+'admin.js'))
        .pipe(gulp.dest('build/assets/admin/js/'))
        .pipe(rename(uniq+'admin.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('build/assets/admin/js/'));
});

But seems the ordering is not working.

the ordering is base on alphabet a.js > z.js instead of jquery.min.js > a.js > z.js

is there anything I'd code wrongly on the gulpfile.js?

Share Improve this question edited Jul 12, 2015 at 17:38 Mavichow asked Jul 12, 2015 at 17:31 MavichowMavichow 1,22317 silver badges42 bronze badges 2
  • gulp-order is working exactly as expected.. it order files by their name and does not consider their position in the input source.. it does not have any way of exclude file from ordering or keep these files at top kind of functionality... – harishr Commented Jul 13, 2015 at 15:40
  • 1 to inject jquery etc... you should use gulp-wiredep... and just order files that you develop... wiredep will order files based on dependency graph – harishr Commented Jul 13, 2015 at 15:41
Add a ment  | 

2 Answers 2

Reset to default 12

adding base option fixed it for me:

.pipe(order([
      'public/js/jquery-1.11.1.min.js',
      'public/js/bootstrap.min.js'
    ], { base: './' }))

The problem my gulp-order not ordering properly / not working is because I'd put wrong path, the path should be relative to the js folder:

correct order : jquery.min.js

incorrect order : assets/admin/js/jquery.min.js

var date = new Date();
var uniq = date.getTime();

gulp.task('admin-scripts', function() {
    return gulp.src(['assets/admin/js/*.js','!assets/admin/js/respond.min.js','!assets/admin/js/html5shiv.js'])
        .pipe(order([
            "jquery.min.js",
            '*.js'
        ]))
        .pipe(concat(uniq+'admin.js'))
        .pipe(gulp.dest('build/assets/admin/js/'))
        .pipe(rename(uniq+'admin.min.js'))
        .pipe(uglify())
        .pipe(gulp.dest('build/assets/admin/js/'));
});
发布评论

评论列表(0)

  1. 暂无评论