本文介绍了复制/删除Gulp随机给ENOENT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

新的Gulp。我的默认任务使用插件 run-sequence ,它告诉任务 deleteBuild 运行,然后 makeBuild



随机地,我得到一个 ENOENT 这似乎是告诉我,我要么参考不存在的文件删除或复制的错误。我的任务是:
$ b $ p deleteBuild

  gulp.task('deleteBuild',function(done){
var del = require('del');
del(['build / ** / *'],done);
});

makeBuild

  gulp.task('makeBuild',function(){
var stream = gulp.src(['src / ** / *'],{base:' src /'})
.pipe(gulp.dest('build /');
});

有人可以告诉我如何最好地解决这个问题吗?我希望寻求低层次的理解,而不是被解释为没有解释的解决方案。 >

Aside :我尝试了没有回调函数的 deleteBuild 假设,它会执行删除操作,并且只有在完成后才能继续执行下一个任务,但这似乎不是正在发生的事情。

deleteBuild 没有返回一个gulp流,从而导致管道损坏。 :

  gulp.task('deleteBuild ',function(){
var del = require('del');
var vinylPaths = require('vinyl-paths');

return gulp.src(['build'])//不需要glob,只需删除build目录
.pipe(vinylPaths(del));
});

gulp.task('makeBuild',function(){
var stream = gulp.src(['src / ** / *'],{base:'src /'} )
.pipe(gulp.dest('build /');
});

gulp.task('default',function(cb){
var runSequence = require('run-sequence');

runSequence('deleteBuild',['makeBuild'],cb);
});

$ b

在执行之前,这些任务将首先删除 build > makeBuild 任务。



您需要安装一个额外的插件:

  npm install vinyl-paths 

,请看一看的大文件。这适用于我; - )


New to Gulp. My default task is using the pluginrun-sequence which tells task deleteBuild to run, then makeBuild.

Randomly, I am getting an ENOENT error which seems to be telling me that I'm either referencing files that don't exist for deletion or copy. My tasks are:

deleteBuild:

gulp.task('deleteBuild', function(done) {
  var del = require('del');
  del(['build/**/*'], done);
});

makeBuild:

gulp.task('makeBuild', function() {
  var stream = gulp.src(['src/**/*'], { base: 'src/' })
    .pipe(gulp.dest('build/');
});

Can someone inform me as to how to best address this issue? I'm hoping to seek a low-level understanding rather than to be shown a solution w/o an explanation. Thanks.

Aside: I tried the deleteBuild without a callback function as well, under the assumption that, as is, it would perform the deletion and only continue to the next task once it is complete, though this doesn't seem to be what is happening.

解决方案

That's probably because the deleteBuild does not return a gulp stream and thus leave the pipe broken. I would propose the following:

gulp.task('deleteBuild', function() {
  var del = require('del');
  var vinylPaths = require('vinyl-paths');

  return gulp.src(['build']) // no need for glob, just delete the build directory
    .pipe(vinylPaths(del));
});

gulp.task('makeBuild', function() {
  var stream = gulp.src(['src/**/*'], { base: 'src/' })
    .pipe(gulp.dest('build/');
});

gulp.task('default', function(cb) {
  var runSequence = require('run-sequence');

  runSequence('deleteBuild', ['makeBuild'], cb);
});

These tasks will first delete the build directory before executing the makeBuild task.

You'll need to install one additional plugin:

npm install vinyl-paths

For a ready to use example, please take a look a the gulpfile of skeletonSPA. This works for me ;-)

这篇关于复制/删除Gulp随机给ENOENT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 23:09