具有合并流的gulp-order节点模块

dto*_*efp 6 concat node.js angularjs node-modules gulp

我正在使用gulp-order模块以及event-streams模块和gulp-concat将javascript文件连接到单个dest文件中.gulp-order插件在我想要以不同顺序连接流中的文件的其他项目中对我很有用.由于某些原因,在这个项目中,它无法正常工作,并且public/angular/config目录中的文件分散在我指定的文件中,以便在public/js目录中最后连接.我认为这可能与指定多个来源有关.angular和js目录.我尝试将流与事件流模块合并而没有运气,而当我第一次开始时,我通过将数组传递给gulp.src函数来指定多个源

gulp.src(['./public/angular/**/*.js', './public/js/*.js'])
Run Code Online (Sandbox Code Playgroud)

下面是我现在使用的代码.管道和连接工作正常,但顺序不符合规范:

var gulp         = require('gulp');
var concat       = require('gulp-concat');
var notify       = require('gulp-notify');
var handleErrors = require('../util/handleErrors');
var jshint       = require('gulp-jshint');
var ngmin        = require('gulp-ngmin');
var order        = require('gulp-order');
var es           = require('event-stream');

function getStream(streamPath) {
  return gulp.src(streamPath);
};

gulp.task('scripts', function() {
    return es.merge(getStream('./public/angular/**/*.js'),getStream('./public/js/*.js'))
        .pipe(order([
          './public/angular/config/*.js',
          './public/angular/services/**/*.js',
          './public/angular/modules/**/*.js',
          './public/angular/primitives/**/*.js',
          './public/js/**/*.js'
        ]))
        .pipe(concat('app.js'))
        .pipe(gulp.dest('./public/build/js'))
        .on('error', handleErrors);
});
Run Code Online (Sandbox Code Playgroud)

Cli*_*ell 12

我有同样的问题,我曾经gulp-print在我的流中看到文件名,但它们是正确的.我发现我需要添加base选项gulp-order,然后一切运行良好.

gulp.src(['myFiles/*', 'myOtherFiles/*'])
   .pipe(order([
      'myOtherFiles/lib1.js',
      'myFiles/lib2.js'
   ], {base: '.'});
Run Code Online (Sandbox Code Playgroud)

有用的文章:http://martinwolf.org/2014/08/12/force-a-concatenation-order-with-gulp-js/

更新:博客文章的新链接:https://martinwolf.org/blog/2014/08/force-a-concatenation-order-with-gulp-js