【问题标题】:gulp-changed has different behavioursgulp-changed 有不同的行为
【发布时间】:2015-07-03 12:43:26
【问题描述】:

在我的网站构建过程中,我使用 gulp-changed 来防止在不必要时执行所有任务。但是,有时即使声明相似,它也会有不同的行为。

有谁知道我做错了什么?

案例 1:使用部分构建 htlm / php。 工作正常!任务进程只有第一次,如果我连续运行两次

gulp.task('pages', function () {

    var toBuild = src + config.pages.src_pages; // many php/html files
    var partials = src + config.pages.src_partials; // "to be included"
    var DEST = target;

    return gulp.src([toBuild, "!" + partials])
        .pipe(changed(DEST))
        .pipe(fileinclude({  prefix: '@@', basepath: '@file' }))
        .pipe(size())
        .pipe(gulp.dest(DEST));
});

案例 2:从多个 svg 文件构建一个 SVG 精灵。 不起作用!如果我连续运行两次,任务会再次运行

gulp.task('vector', function () {

   var DEST = target + config.assets.images.vector_dest; 
   var configsvg = { // ... config stuff // };

   return gulp.src(src + config.assets.images.vector_src)
        .pipe(changed(DEST))
        .pipe(svgo())
        .pipe(svgSprite(configsvg)).on('error', function (error) {
            console.log(error);
        })
        .pipe(size())
        .pipe(gulp.dest(DEST));
});

【问题讨论】:

    标签: html svg sprite gulp


    【解决方案1】:

    解决方案是在“多对一”文件编译(连接等...)的情况下使用 gulp-newer 模块

    感谢林 H。 gulp-newer vs gulp-changed

    【讨论】:

      【解决方案2】:

      我还可以建议gulp-newy 在其中您可以在自己的函数中操作路径和文件名。然后,只需将该函数用作newy() 的回调。这使您可以完全控制要比较的文件。

      这将允许 1:1 或多对 1 比较。

      newy(function(projectDir, srcFile, absSrcFile) {
        // do whatever you want to here. 
        // construct your absolute path, change filename suffix, etc. 
        // then return /foo/bar/filename.suffix as the file to compare against
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-22
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多