【发布时间】:2016-09-12 14:03:23
【问题描述】:
当我尝试 gulp.src 从 gulp.watch 获得的已更改文件的路径时,Gulp (4.0) 会引发错误 "Error: Invalid glob argument: undefined"。这两个:
gulp.task('watch', function() {
gulp.watch('./web/**/*.html')
.on('change', function(file) {
gulp.src(file.path)
.pipe(gulp.dest('./output'));
});
});
还有这个语法变体:
gulp.task('watch', function() {
gulp.watch('./web/**/*.html', function(file) {
gulp.src(file.path)
.pipe(gulp.dest('./output'));
});
});
产生相同的结果。
gulp.src 之前的记录 file.path 也输出“未定义”。
复制:
npm install -g gulp@github:gulpjs/gulp#4.0
并创建一个gulpfile.js,其中包含:
const gulp = require('gulp');
后面是两个例子。
我的理解是,这就是更改文件路径应该可以访问的方式as per the docs,所以我不确定我哪里出错了?
【问题讨论】: