gulp - gulp 合并流只添加一个
问题描述
我有一个 gulp 方法,可以成功地从一个 html 文件中获取内容并注入到指定的 src 文件中,然后输出到一个目录。
我现在处于需要将两个不同文件中的 html 注入到一个文件中的位置,例如 FormMaster.html 应该有从 FormChildOne.html 和 FormChildTwo.html 注入的代码。
我尝试过使用合并流、事件流和流队列,但我得到的最远的是当前状态:
async function forms() {
var injectOptions = {
starttag: '<!-- inject:lastesthtml -->',
endtag: '<!-- endinject -->',
transform: function (filePath, file) {
return file.contents.toString('utf8')
}
};
var stream1;
var stream2;
stream1 = src(`${origin}/Example/TestForm/FormMaster.html`)
.pipe(flatmap(function (stream, file) {
var html = src(
path.join(`${origin}`, '/Example/TestForm/FormChildOne.html')
.split('.')[0] + '.html'
);
return stream
.pipe(inject(
html.pipe(htmlmin({
removeEmptyAttributes: true,
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true,
}))
.pipe(replace(
//some replace code here
))
, injectOptions
))
.pipe(htmlmin({
removeEmptyAttributes: true,
collapseBooleanAttributes: true,
collapseWhitespace: true,
minifyJS: true,
minifyCSS: true,
}))
.pipe(rename(function (path) {
path.extname = ".complete.html";
}))
.pipe(dest(
`${destination}/html/Test1`
));
}));
流 2 类似于流 1,只是引用的文件不同:
var html = src(
path.join(`${origin}`, '/Example/TestForm/FormChildTwo.html')
.split('.')[0] + '.html'
);
而且目的地不同。
stream1 目的地是${destination}/html/Test1
stream2 目的地是${destination}/html/Test2
在stream2之后:
return merge(stream1, stream2)
.pipe(dest(
`${destination}/html/Test3`
));
我在 test1 和 test2 的输出文件中看到了我想要的更改,但显然它们没有合并到一个文件中,它们是两个文件。如果我只是使每个流的目的地相同,我只会得到一个流的结果。
我希望流合并能解决这个问题,但我仍然只看到合并目标中的两个流更改之一。我不知道这是为什么或如何解决它。
解决方案
推荐阅读
- javascript - 当输入字段在反应js中成为焦点时如何更改标签颜色
- spring - 使用执行器/关闭与 SIGTERM 优雅地终止 Spring 应用程序有什么区别?
- java - 任何视图上的 setText()
- bash - 反斜杠在反引号中究竟是如何工作的?
- android-room - 如何迁移房间数据库中长列的步骤?
- javascript - Angular 7 - 为 primeNg 菜单栏实现键盘快捷键
- python - 有没有办法接受参数选择作为单个字符串
- reactjs - 使用移除的 Babel 5 选项:base.modules - 使用相应的模块转换插件
- javascript - 我无法让我的应用使用组件文件中的 navigationOptions 而不是路由
- tensorflow - 一旦 CNN 被训练,它的输出是否应该是确定性的?