javascript - 使用 gulp-htmlbuild 而不将所有文件连接到单个文件中

标签 javascript html build gulp

我想要:

  1. 读取htmlbuild:js block 中的所有js文件
  2. 将它们通过管道输送到一系列构建步骤中,例如丑化、语法检查......,
  3. 将它们复制(同时保留其目录结构)到目标文件夹(实际上是 html 构建目标)
  4. 再次在 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/

相关文章:

javascript - 如何在 useState Hook 中将字符串转换为数字?

javascript - 如何在js中解析json?

html - "stick"内容到底部页面,不是视口(viewport),具有自动高度

html - 在游戏中的 View 中使用 Future 2.3.2

c - g++-4.6.real : error: unrecognized option '-R'

javascript - 使用 svg.js 将生成的 SVG 保存为 .svg 文件

javascript - 登录sharetribe后sharetribe主页错误

html - 从 Angular 2 中的变量设置组件样式

reporting-services - 用于将SSRS项目报告RDL模式从2016转换为2008版本的构建工具

tfs - 内部版本号格式,四位修订号