具有合并流的 gulp-order 节点模块 [英] gulp-order node module with merged streams

查看:23
本文介绍了具有合并流的 gulp-order 节点模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the gulp-order module along with the event-streams module and gulp-concat to concatenate javascript files into a single dest file. The gulp-order plugin has worked great for me in other projects where I wanted to concatenate files from the stream in a distinct order. For some reason in this project it is not working properly, and the files in the public/angular/config directory are dispersed amongst the files I specify to concatenate last in the public/js directory. I think this may have something to do with specifying multiply sources ie. the angular and js directories. I tried merging the streams with the event-streams module with no luck, whereas when I first began I specified the multiple sources by passing an array to the gulp.src function

gulp.src(['./public/angular/**/*.js', './public/js/*.js'])

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

Below is the code I'm using now. The piping and concatenation are working fine but the order is not following the specification:

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

推荐答案

我遇到了同样的问题,我使用 gulp-print 查看流中的文件名,但它们是正确的.我发现我需要将 base 选项添加到 gulp-order 中,然后一切正常.

I had this same issue, and I used gulp-print to see the filenames in my stream, but they were correct. I found out that I needed to add the base option to gulp-order, then all worked well.

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

有用的文章: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

这篇关于具有合并流的 gulp-order 节点模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆