首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在babel.js中使用杯式手表

在babel.js中使用杯式手表
EN

Stack Overflow用户
提问于 2015-04-07 13:41:48
回答 1查看 2.4K关注 0票数 2

下面是一项ES6溢出任务。它工作得很好,但我正在尝试用gulp.watch替换它,这样就可以捕捉到新的文件。问题是,gulp.watch并没有告诉我gulp.watch在回调中做了什么,我也不知道该怎么办。

这是我最初的工作任务:

代码语言:javascript
复制
var gulp = require('gulp'),
    rename = require('gulp-rename'),
    plumber = require('gulp-plumber'),
    gprint = require('gulp-print'),
    notify = require('gulp-notify'),
    babel = require('gulp-babel');

gulp.task('default', function() {
    return gulp.watch('../**/**-es6.js', function(obj){
        if (obj.type === 'changed') {
            gulp.src(obj.path, { base: './' })
                .pipe(plumber({
                    errorHandler: function (error) { /* elided */ }
                }))
                .pipe(babel())
                .pipe(rename(function (path) {
                    path.basename = path.basename.replace(/-es6$/, '');
                }))
                .pipe(gulp.dest(''))
                .pipe(gprint(function(filePath){ return "File processed: " + filePath; }));
        }
    });
});

到目前为止,我所拥有的只是一只大表:

代码语言:javascript
复制
var gulp = require('gulp'),
    rename = require('gulp-rename'),
    plumber = require('gulp-plumber'),
    gprint = require('gulp-print'),
    notify = require('gulp-notify'),
    babel = require('gulp-babel'),
    gWatch = require('gulp-watch');

gulp.task('default', function() {
    return gWatch('../**/**-es6.js', function(obj){
        console.log('watch event - ', Object.keys(obj).join(','));
        console.log('watch event - ', obj.event);
        console.log('watch event - ', obj.base);

        return;
        if (obj.type === 'changed') {
            gulp.src(obj.path, { base: './' })
                .pipe(plumber({
                    errorHandler: function (error) { /* elided */ }
                }))
                .pipe(babel())
                .pipe(rename(function (path) {
                    path.basename = path.basename.replace(/-es6$/, '');
                }))
                .pipe(gulp.dest(''))
                .pipe(gprint(function(filePath){ return "File processed: " + filePath; }));
        }
    });
});

日志记录的输出如下:

监视事件-历史记录,cwd,base,stat,_contents,event 手表事件-更改 看比赛- ..。

我怎样才能让手表给我以前的信息,或者,我怎样才能改变我的任务代码,让这个任务再次工作呢?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-07 14:05:21

根据测试obj.relative应该包含相对文件名,而obj.path仍然保持绝对文件路径,就像它在原始代码中所做的那样。此外,回调还接受Vinyl对象,这在这里有文档:https://github.com/wearefractal/vinyl

您可能无法在日志中看到它们,因为Object.keys没有枚举原型链中的属性。

使用for..in循环,您应该能够看到所有属性。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29493057

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档