Gulp dest:如果2个任务尝试写入相同的目标,则发出警告 [英] Gulp dest: warn if 2 tasks try to write to the same destination

查看:131
本文介绍了Gulp dest:如果2个任务尝试写入相同的目标,则发出警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在这个例子中,有一个 / js 目录旁边有一个 / ts 目录。 / ts 将被转移到与 / js 相同的目录中。不应该有任何碰撞。问题是,如果发生冲突, ts 将会获胜;但是,我想警告说有冲突。
$ b $

  gulp.task('js',function(){
返回es.concat(
gulp.src(config.src.path('js','**','* .js'))
.pipe(gulp.dest(config .build.path(app,'js')))
//,....
);
});

gulp.task('ts',['js'],function(){

var tsResult = gulp.src(config.src.path('ts' ,'**','* .ts'))
.pipe(ts({
declaration:true,
noExternalResolve:true
}));

return es.concat([
tsResult.dts.pipe(gulp.dest(
config.build.path(app,'definitions'))),

tsResult.js.pipe(gulp.dest(
config.build.path(app,'js')))//< ---与js任务
相同);

))

我可以检测到 ts 任务正在覆盖 js 任务刚才存在的文件?

解决方案

只是一个想法。您可以传递回调

  gulp.src('lib / *。js')
.pipe(uglify())
.pipe(gulp.src('styles / * .css'))
.pipe(gulp.dest(function(file){
if(fs.existsSync('something here')){//这是一个不推荐的调用,使用一个新的
console.warn(File exists,file);
}
/ /我不知道,你可以在这里做一些很酷的事情
return'build / whatever';
}));

该功能自Gulp 3.8开始提供: https://github.com/gulpjs/gulp/blob/master/CHANGELOG.md#380



其他资源:


I wonder if there is an easy way to detect if two tasks write to the same file.

In this example there is a /js directory alongside a /ts directory. The /ts will get transpiled to the same directory as the /js. There shouldn't be any collisions. The ask is that, if there are collisions, the ts will win; but, I would like to warn that there is a collision.

gulp.task('js', function() {
    return es.concat(
        gulp.src(config.src.path('js', '**', '*.js'))
            .pipe(gulp.dest(config.build.path(app, 'js')))
        //, ....
    );
});

gulp.task('ts', ['js'], function() {

    var tsResult = gulp.src(config.src.path('ts', '**', '*.ts'))
        .pipe(ts({
            declaration: true,
            noExternalResolve: true
        }));

    return es.concat([
        tsResult.dts.pipe(gulp.dest(
            config.build.path(app, 'definitions'))),

        tsResult.js.pipe(gulp.dest(
            config.build.path(app, 'js'))) // <--- same dest as js task
    ]);

})

Can I detect that the ts task is overwriting a file that the js task just put in place?

解决方案

Just an idea. You can pass a callback to gulp.dest like this:

gulp.src('lib/*.js')
  .pipe(uglify())
  .pipe(gulp.src('styles/*.css'))
  .pipe(gulp.dest(function(file) {
    if (fs.existsSync('something here')) { // it's a deprecated call, use a newer one
       console.warn("File exists", file);
    }
    // I don't know, you can do something cool here
    return 'build/whatever';
  }));

The feature is available since Gulp 3.8: https://github.com/gulpjs/gulp/blob/master/CHANGELOG.md#380

Other resources:

这篇关于Gulp dest:如果2个任务尝试写入相同的目标,则发出警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆