有没有一种方法可以让watch函数获取被监视文件的名称
Is there a way to have a watch function get the name of the file being watched?
我已经对这三块手表进行了编码,但还需要编码更多:
gulp.task('fl-index', function () {
gulp.watch('index-fl.html', function () {
return gulp.src('index-fl.html')
.pipe(rename('index.html'))
.pipe(gulp.dest('./'));
})
});
gulp.task('ic-index', function () {
gulp.watch('index-ic.html', function () {
return gulp.src('index-ic.html')
.pipe(rename('index.html'))
.pipe(gulp.dest('./'));
})
});
gulp.task('ts-index', function () {
gulp.watch('index-ts.html', function () {
return gulp.src('index-ts.html')
.pipe(rename('index.html'))
.pipe(gulp.dest('./'));
})
});
由于所有的功能几乎都是一样的,我想知道我是否有可能以某种方式将其组合成一口吞下的任务?
每次发生更改时,传递给gulp.watch()
的函数都会接收一个对象,该对象包含指向受影响文件的path
属性。
您可以使用它来统一您的三项任务:
var gulp = require('gulp');
var rename = require('gulp-rename');
var path = require('path');
gulp.task('index', function () {
gulp.watch('index-*.html', function (file) {
return gulp.src(path.basename(file.path))
.pipe(rename('index.html'))
.pipe(gulp.dest('./'));
})
});
相关文章:
- Javascript:如何获取函数.apply()的键
- 如何在 JavaScript 中获取函数体文本
- 从函数内部获取函数的名称
- 从字符串的 JS 函数中获取函数参数
- 获取函数中按钮的名称
- 在其参数中获取函数本身
- 如何获取函数元素中的值
- 获取函数原型的源代码
- javascript:获取函数's变量's在另一个函数中的值
- 无法获取函数的ajax回调
- Javascript通过名称获取函数
- 如何获取函数参数值
- 使用Rhino从已评估的JS中获取函数名及其参数
- 获取函数jQuery设置的属性
- 获取函数的arity
- AJAX请求在jQuery中获取函数,变量问题
- 获取函数的表单隐藏变量
- 如何从外部JavaScript文件获取函数参数
- 不要在 Codeigniter 中获取函数参数
- 客户端 JavaScript 从服务器端文档集和获取函数接收过时的值