从多个流创建单个文件,同时使用Gulp保持流和文件顺序

时间:2023-01-24 11:28:11

I have a Gulp task where I would like to compile HTML templates to javascript (lets say from /views directory), add all other javascript sources to this (from /js directory) and concatenate all of them into one single file.

我有一个Gulp任务,我想将HTML模板编译为javascript(从/ views目录中说),将所有其他javascript源添加到此(来自/ js目录)并将所有这些源连接到一个文件中。

Its also important to have the files concatenated in the correct order, meaning: all files from /js then all compiled files from /views.

将文件以正确的顺序连接起来也很重要,这意味着:来自/ js的所有文件然后来自/ views的所有编译文件。

My goal is to avoid creating temporary files in general, so the solution I seek only works with streams.

我的目标是避免一般创建临时文件,因此我寻求的解决方案仅适用于流。

This task currently works without correctly ordering the output:

此任务当前无法正确排序输出:

var eventstream = require('event-stream');
gulp.task('dist', function()
{
    return eventstream.merge(
        gulp.src(['**/[^_]*.js', '!**/_*/**'], { cwd: 'js' })
    ,
        gulp.src(['**/[^_]*.html', '!**/_*/**'], { cwd: 'views' })
        .pipe(compile_views())
    )
    .pipe(concat('output.js'))
    .pipe(gulp.dest('dist'));
});

Tried a few stream merging modules from NPM with less success, all of them scrambled my output so far:

从NPM尝试了一些流合并模块并取得了较少的成功,所有这些模块到目前为止都扰乱了我的输出:

  • multistream
  • stream-series
  • merge-stream
  • ordered-merge-stream

Also tried using the gulp-order plugin after merging the streams, which still does not ordered it correctly.

在合并流之后还尝试使用gulp-order插件,但仍未正确排序。

Did I miss something, or am I doing something the bad way? I'm not so expert in pipes yet.

我错过了什么,还是我做了一些糟糕的事情?我还不是那么擅长管道。

Any help would be appreciated!

任何帮助,将不胜感激!

Thanks!

1 个解决方案

#1


1  

I think streamqueue is what you're looking for:

我认为streamqueue是你正在寻找的:

var streamqueue = require('streamqueue');

gulp.task('dist', function() {
  return streamqueue({ objectMode: true },
    gulp.src(['**/[^_]*.js', '!**/_*/**'], { cwd: 'js' }),
    gulp.src(['**/[^_]*.html', '!**/_*/**'], { cwd: 'views' })
      .pipe(compile_views())
  )
  .pipe(concat('output.js'))
  .pipe(gulp.dest('dist'));
});

#1


1  

I think streamqueue is what you're looking for:

我认为streamqueue是你正在寻找的:

var streamqueue = require('streamqueue');

gulp.task('dist', function() {
  return streamqueue({ objectMode: true },
    gulp.src(['**/[^_]*.js', '!**/_*/**'], { cwd: 'js' }),
    gulp.src(['**/[^_]*.html', '!**/_*/**'], { cwd: 'views' })
      .pipe(compile_views())
  )
  .pipe(concat('output.js'))
  .pipe(gulp.dest('dist'));
});