gulp-order : not Ordering properly

独自空忆成欢 提交于 2021-01-27 03:55:32

问题


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?


回答1:


adding base option fixed it for me:

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



回答2:


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/'));
});


来源:https://stackoverflow.com/questions/31370600/gulp-order-not-ordering-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!