gulp.watch() 没有运行后续任务

gulp.watch() not running subsequent task(gulp.watch() 没有运行后续任务)
本文介绍了gulp.watch() 没有运行后续任务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试将模块化 gulp 任务拆分为单独的文件时遇到了一个奇怪的错误.以下应该执行任务 css,但不执行:

Running into a bizarre bug when trying to make modular gulp tasks by splitting them into separate files. The following should execute the task css, but does not:

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();

gulp.task('watch', function () {
  plugins.watch('assets/styl/**/*.styl', ['css']); // PROBLEM
});

plugins.watch() 中声明 ['css'] 在技术上应该接下来运行以下任务:

Declaring ['css'] in plugins.watch() should technically run the following task next:

var gulp = require('gulp');
var plugins = require('gulp-load-plugins')();

gulp.task('css', function () {
  return gulp.src('assets/styl/*.styl')
    .pipe(plugins.stylus())
    .pipe(gulp.dest('/assets/css'));
});

文件:gulpfile.js

var gulp = require('gulp');
var requireDir = require('require-dir');
requireDir('./gulp/tasks', { recurse: true });

gulp.task('develop', ['css', 'watch']);

文件夹结构

<代码>- 吞咽/- 任务/-css.js- watch.js-gulpfile.js

gulp develop 应该运行任务 csswatch(确实如此).在文件更改时,watch 应该检测到它们(它会)然后运行 ​​css 任务(它不会).

gulp develop should run tasks css and watch (it does). On file changes, watch should detect them (it does) and then run the css task (it's does not).

不太喜欢这个解决方案,因为 gulp.start() 在下一个版本中被弃用,但这确实解决了它:

Not terribly fond of this solution as gulp.start() is being deprecated in the next release, but this does fix it:

plugins.watch('assets/styl/**/*.styl', function() {
  gulp.start('css');
});

推荐答案

要么使用gulp的内置手表,语法如下:

Either use gulp's builtin watch with this syntax:

gulp.task('watch', function () {
  gulp.watch('assets/styl/**/*.styl', ['css']);
});

或 gulp-watch插件 使用这种语法:

gulp.task('watch', function () {
  plugins.watch('assets/styl/**/*.styl', function (files, cb) {
    gulp.start('css', cb);
  });
});

您的 gulp.dest 路径中也可能有错字.将其更改为相对:

There's also probably a typo in your gulp.dest path. Change it to relative:

.pipe(gulp.dest('assets/css'));

这篇关于gulp.watch() 没有运行后续任务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)