简体   繁体   English

Gulp循环执行监视任务

[英]Gulp looping a watch task

I'm new in Gulp and this is my code that just minifies my JS script: 我是Gulp的新手,这是我的代码,仅能简化我的JS脚本:

gulp.task('minify-js', function(){
    return gulp.src(['assets/js/**/*.js', '!assets/js/**/*.min.js'])
    .pipe(uglify())
    .pipe(rename({ suffix: '.min' }))
    .pipe(gulp.dest('./assets/js'))
});
gulp.task('watch', function(){
    //gulp.watch(['sass/**/*.sass'], gulp.series('css-files'));
    gulp.watch(['assets/js/**/*.js'], gulp.series('minify-js'));
});

gulp.task('default', gulp.series('watch'));

When I run gulp default and edit any JS file, my task starts looping for no reason and the files keep being minified and merged aswell. 当我运行gulp default并编辑任何JS文件时,我的任务无缘无故地开始循环,并且文件也不断缩小和合并。 Why? 为什么? It should stop after one execution! 它应该在执行一次后停止!

example: 例: 在此处输入图片说明

*This code runs perfectly without the watch task *此代码无需监视任务即可完美运行

Any help? 有什么帮助吗?

Your destination file matches the mask of source files. 您的目标文件与源文件的掩码匹配。

So Gulp process the file it just generated themself. 所以Gulp处理它自己生成的文件。 And then again, and again. 然后一次又一次。

Update : you've excluded the file in minify-js task, but not excluded in watch task. 更新 :您已在minify-js任务中排除了该文件,但未在watch任务中排除了该文件。 Set watch argument the same as for minify-js and that should help. watch参数设置为与minify-js相同,应该会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM