-6ren">
gpt4 book ai didi

一口哈巴狗 : compile new on changed files only (case with "includes" and "extends")

转载 作者:行者123 更新时间:2023-12-05 06:34:42 24 4
gpt4 key购买 nike

考虑以下文件系统:

📁哈巴狗

‖test1.pug

‖test2.pug

‍‍‍📁 部分内容

‍‍‍‍partial1.pug

使用 gulp 任务

gulp.task('pug', () => {
return gulp.src('pug/*.pug')
.pipe(pug())
.pipe(gulp.dest('dist'))
});

即使我们只编辑 test1.pugtest1.pugtest2.pug 也会被编译。如果将任务更改为

gulp.task('pug', () => {
return gulp.src('pug/*.pug', {since: gulp.lastRun('pug')})
.pipe(pug())
.pipe(gulp.dest('dist'))
});

gulp-watch 运行第二个 'pug' 以来,只有更改的或新的文件才会被传递。但是,如果 partial1.pug 已包含在 test1.pug 中怎么办? (假设 gulp.watch 观察所有文件)。

test1.pug

doctype html
html
head
title Test 1
body
h1 Test 1
include partials/partial1.pug

如果我们编辑test1.pug,它当然会被编译。但是,如果我们编辑 partial1.pug,test1.pug 将不会被 {since: gulp.lastRun('pug')} 传递。

我不知道,如何解决这个问题,但我想,我们需要在输出之前从文件或已编译的 html 中过滤组装的 pug。如果可能的话……

更新

也许我没有把想要的结果解释清楚。我们需要:

  • test1.pug 已编辑 → 仅编译 test1.pug
  • partial1.pug 已被编辑 → 仅编译 test1.pug
  • test2.pug 已编辑 → 仅编译 test2.pug

让我重复一遍,partial1.pug 包含在 test1.pug 中,但不包含在 test2.pug 中。

最佳答案

src 模式之外的依赖项在这个阶段不可用以供观察。它们稍后被添加到管道中(通过 pug())。为了支持您的用例,Gulp 需要有一种方法从下游转换器收集依赖项。目前这不属于 Gulp 的范围(这是一个复杂的行为,有许多可能的设计选择)。

您的问题的最佳解决方案是手动更新您的 src 模式以匹配您的整个依赖关系树。在您的情况下,它将是 pub/**/*.pug。 (wildstar ** 允许您匹配任何子目录中的文件)。

您还可以查看实现 your own watcher以获得更好的控制(我担心我上面的模式可能会为您的部分生成 HTML)。

关于一口哈巴狗 : compile new on changed files only (case with "includes" and "extends"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50165810/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com