我想要:
- 读取htmlbuild:js block 中的所有js文件
- 将它们通过管道输送到一系列构建步骤中,例如丑化、语法检查......,
- 将它们复制(同时保留其目录结构)到目标文件夹(实际上是 html 构建目标)
- 再次在 htmlbuild:js 中添加所有内容的链接
default example of the package中的用例与我想要的类似,但它不是第 3 步和第 4 步,而是简单地将所有这些连接到具有预定义名称的单个文件中,并写入指向该文件的单个脚本标记。
最佳答案
您在 htmlbuild 回调函数中收到的 block
是一个可写流。无论您写入什么内容,最终都会替换该 block 。在本例中,只有一个路径写入其中,但没有什么可以阻止您写入多个路径:
// then write the build result path to it
block.write('path1.js');
block.write('path2.js');
block.write('path3.js');
block.write('path4.js');
block.end();
由于它也是一个可读流,因此您可以将其通过管道传递给自身或对其应用转换:
// First build the files that are in the block
block
.pipe(buildSteps)
.pipe(gulp.dest(targetDir));
// Then rename all the paths and write back to the block
block
.pipe(renameToDestination)
.pipe(block);
在此示例中,renameToDestination
将是一个转换流,它接受字符串形式的路径并将其重命名为目标目录。
关于javascript - 使用 gulp-htmlbuild 而不将所有文件连接到单个文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30951065/