'... paths.js'在'gulp.src([... paths.js,'!gulpfile.babel.js'],{base:'.'}}'中的含义是什么?

Col*_*amp 4 javascript node.js ecmascript-6 gulp

我有以下gulp任务:

// Compile ES6 to ES5 and copy to dist
gulp.task('babel', () =>
  gulp.src([...paths.js, '!gulpfile.babel.js'], { base: '.' })
    .pipe(plugins.newer('dist'))
    .pipe(plugins.sourcemaps.init())
    .pipe(plugins.babel())
    .pipe(plugins.sourcemaps.write('.', {
      includeContent: false,
      sourceRoot(file) {
        return path.relative(file.path, __dirname);
      }
    }))
    .pipe(gulp.dest('dist'))
);
Run Code Online (Sandbox Code Playgroud)

根据Gulp Doc(gulp.src),我了解到gulp.src会发出匹配提供的glob或glob数组的文件.
但我无法理解'... paths.js'的含义.项目目录中没有以"paths.js"命名的文件.

有没有人可以帮助我理解它?

T.J*_*der 5

...在该上下文中是ES2015(又名"ES6")扩展语法:它采用可迭代的内容(如数组)并将其扩展为数组中的离散元素.

例:

let a = [1, 2, 3];
let b = [...a, 4, 5];
console.log(b); // 1, 2, 3, 4, 5
Run Code Online (Sandbox Code Playgroud)

所以

gulp.src([...paths.js, '!gulpfile.babel.js'], { base: '.' })
Run Code Online (Sandbox Code Playgroud)

...正在创建一个新数组,其中包含paths.js后跟'!gulpfile.babel.js'并传递该数组的内容src.我假设paths.js是一个数组; 如果是这样,在这种特殊情况下,它可以替换为concat:

gulp.src(paths.js.concat('!gulpfile.babel.js'), { base: '.' })
Run Code Online (Sandbox Code Playgroud)

您还可以在函数调用中使用扩展语法:

function testing(a, b, c) {
  console.log("a = " + a);
  console.log("b = " + b);
  console.log("c = " + c);
}
let x = [1, 2, 3];
testing(...x);  // Shows:
                // a = 1
                // b = 2
                // c = 3
Run Code Online (Sandbox Code Playgroud)