简体   繁体   English

Gulp,将把手模板与其他源文件合并?

[英]Gulp, merge handlebars templates with other source files?

I wan't to merge (concatenate) Handlebars, Libraries (jQuery and what have you) and custom javascript into one single js file. 我不会将手把,库(jQuery和您拥有的东西)和自定义javascript合并(合并)到一个单独的js文件中。 But it seems a handlebars task will convert any source to compiled 'handlebars' code. 但是似乎一个handlebars任务会将任何源都转换为已编译的“ handlebars”代码。 I've been looking at listening for the end event, and then manually go to all the different source locations, but that'll be a mess. 我一直在寻找结束事件,然后手动转到所有不同的源位置,但这很混乱。

How can I merge all these kinds of files from various destinations into one single file, without manually merging files after run tasks (leaving output all over the place). 如何将来自各种目标的所有这些类型的文件合并到一个文件中,而无需在运行任务后手动合并文件(将输出保留在所有位置)。 Passing multiple source paths to a handlebars task is obviously a no go? 将多个源路径传递到把手任务显然是行不通的吗?

You can merge two gulp streams using merge-stream 您可以使用merge-stream合并两个gulp

var merge      = require('merge-stream');
var gulp       = require('gulp');
var concat     = require('gulp-concat');
var handlebars = require('gulp-handlebars');

gulp.task('scripts', function () {
  var hbsStream = gulp.src('templates/*.hbs').pipe(handlebars());
  var jsStream  = gulp.src('scripts/*.js');
  return merge(hbsStream, jsStream).pipe(concat('scripts.js'));
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM