使用 gulp-htmlbuild 而不将所有文件连接成一个文件

using gulp-htmlbuild without concatenating all files into a single file

我想:

  1. 读取htmlbuild:js块中的所有js文件
  2. 将它们输送到一系列构建步骤中,例如丑化、语法检查、....,
  3. 将它们(同时保留它们的目录结构)复制到目标文件夹(html 实际上是构建目标)
  4. 再次将 link 添加到 htmlbuild:js 中的所有对象

default example of the package中的用例与我想要的类似,但它不是第 3 步和第 4 步,而是简单地将它们全部连接到一个具有预定义名称的文件中,并写入一个脚本标记指向到那个文件。

您在 htmlbuild 回调函数中收到的 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 将是一个转换流,它将路径作为字符串接受并将它们重命名为目标目录。