Gulp 如何使用大口更新?

Gulp 如何使用大口更新?,gulp,gulp-newer,Gulp,Gulp Newer,我是gulp的新手,我试着按照中的文档来理解它是如何工作的。但是,对于下面的任务,它不能按预期工作。我想我遗漏了一些明显的东西 这是文件夹结构 temp file1.js file2.js new file1.js file3.js change <empty initially> 然而,当我运行这个任务时,它只是将临时文件夹中的所有文件复制到更改文件夹中。所以在任务运行后,更改文件夹有file1.

我是gulp的新手,我试着按照中的文档来理解它是如何工作的。但是,对于下面的任务,它不能按预期工作。我想我遗漏了一些明显的东西

这是文件夹结构

    temp
      file1.js
      file2.js
    new
      file1.js
      file3.js
    change
      <empty initially>
然而,当我运行这个任务时,它只是将临时文件夹中的所有文件复制到更改文件夹中。所以在任务运行后,更改文件夹有file1.js和file2.js。我只希望file3.js出现在变更中(因为这是一个新文件)。如果我对该方法的理解不正确,请更正。

发件人:

使用更新的:1 source:dest映射插件,如gulp concat 获取多个源文件并生成单个目标文件。在这个 在这种情况下,较新的流将通过所有源文件(如果有) 其中一个文件比目标文件更新。更新的插件是 配置了目标文件路径

和示例代码:

var gulp = require('gulp');
var newer = require('gulp-newer');
var concat = require('gulp-concat');

// Concatenate all if any are newer 
gulp.task('concat', function() {

  // Add the newer pipe to pass through all sources if any are newer 
  return gulp.src('lib/*.js')
      .pipe(newer('dist/all.js'))
      .pipe(concat('all.js'))
      .pipe(gulp.dest('dist'));

});
似乎您需要传入所有已连接到较新版本的文件。就你而言:

gulp.task('newer', function() {
        return gulp.src('temp/*.js')
                .pipe(newer('new/*.js'))
                .pipe(concat('*.js'))
                .pipe(gulp.dest('change')) 
        });
此外,由于更新者会检查文件的修改日期,因此请确保文件实际上是更新的。我知道这是显而易见的,但我通常被“显而易见”的东西所困扰。

我还可以建议您在自己的函数中操作路径和文件名。然后,只需将该函数用作对
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
}

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
}