<tfoot id='JOKhc'></tfoot>
  • <legend id='JOKhc'><style id='JOKhc'><dir id='JOKhc'><q id='JOKhc'></q></dir></style></legend>
      <bdo id='JOKhc'></bdo><ul id='JOKhc'></ul>
    1. <small id='JOKhc'></small><noframes id='JOKhc'>

        <i id='JOKhc'><tr id='JOKhc'><dt id='JOKhc'><q id='JOKhc'><span id='JOKhc'><b id='JOKhc'><form id='JOKhc'><ins id='JOKhc'></ins><ul id='JOKhc'></ul><sub id='JOKhc'></sub></form><legend id='JOKhc'></legend><bdo id='JOKhc'><pre id='JOKhc'><center id='JOKhc'></center></pre></bdo></b><th id='JOKhc'></th></span></q></dt></tr></i><div id='JOKhc'><tfoot id='JOKhc'></tfoot><dl id='JOKhc'><fieldset id='JOKhc'></fieldset></dl></div>
      1. Gulp 错误:监视任务必须是一个函数

        时间:2023-05-28
      2. <tfoot id='L3hPG'></tfoot>
        <i id='L3hPG'><tr id='L3hPG'><dt id='L3hPG'><q id='L3hPG'><span id='L3hPG'><b id='L3hPG'><form id='L3hPG'><ins id='L3hPG'></ins><ul id='L3hPG'></ul><sub id='L3hPG'></sub></form><legend id='L3hPG'></legend><bdo id='L3hPG'><pre id='L3hPG'><center id='L3hPG'></center></pre></bdo></b><th id='L3hPG'></th></span></q></dt></tr></i><div id='L3hPG'><tfoot id='L3hPG'></tfoot><dl id='L3hPG'><fieldset id='L3hPG'></fieldset></dl></div>

              <bdo id='L3hPG'></bdo><ul id='L3hPG'></ul>

              <small id='L3hPG'></small><noframes id='L3hPG'>

                <tbody id='L3hPG'></tbody>
                  <legend id='L3hPG'><style id='L3hPG'><dir id='L3hPG'><q id='L3hPG'></q></dir></style></legend>
                  本文介绍了Gulp 错误:监视任务必须是一个函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  这是我的 gulpfile:

                  Here is my gulpfile:

                  // Modules & Plugins
                  var gulp = require('gulp');
                  var concat = require('gulp-concat');
                  var myth = require('gulp-myth');
                  var uglify = require('gulp-uglify');
                  var jshint = require('gulp-jshint');
                  var imagemin = require('gulp-imagemin');
                  
                  // Styles Task
                  gulp.task('styles', function() {
                      return gulp.src('app/css/*.css')
                          .pipe(concat('all.css'))
                          .pipe(myth())
                          .pipe(gulp.dest('dist'));
                  });
                  
                  // Scripts Task
                  gulp.task('scripts', function() {
                      return gulp.src('app/js/*.js')
                          .pipe(jshint())
                          .pipe(jshint.reporter('default'))
                          .pipe(concat('all.js'))
                          .pipe(uglify())
                          .pipe(gulp.dest('dist'));
                  });
                  
                  // Images Task
                  gulp.task('images', function() {
                      return gulp.src('app/img/*')
                          .pipe(imagemin())
                          .pipe(gulp.dest('dist/img'));
                  });
                  
                  // Watch Task
                  gulp.task('watch', function() {
                      gulp.watch('app/css/*.css', 'styles');
                      gulp.watch('app/js/*.js', 'scripts');
                      gulp.watch('app/img/*', 'images');
                  });
                  
                  // Default Task
                  gulp.task('default', gulp.parallel('styles', 'scripts', 'images', 'watch'));
                  

                  如果我单独运行 imagesscriptscss 任务,它就可以工作.我必须在任务中添加 return - 这不在书中,但谷歌搜索告诉我这是必需的.

                  If I run the images, scripts or css task alone it works. I had to add the return in the tasks - this wasn't in the book but googling showed me this was required.

                  我遇到的问题是 default 任务错误:

                  The problem I have is that the default task errors:

                  [18:41:59] Error: watching app/css/*.css: watch task has to be a function (optionally generated by using gulp.parallel or gulp.series)
                      at Gulp.watch (/media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/node_modules/gulp/index.js:28:11)
                      at /media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/gulpfile.js:36:10
                      at taskWrapper (/media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/node_modules/undertaker/lib/set-task.js:13:15)
                      at bound (domain.js:287:14)
                      at runBound (domain.js:300:12)
                      at asyncRunner (/media/sf_VM_Shared_Dev/webdevadvlocal/gulp/public_html/gulp-book/node_modules/async-done/index.js:36:18)
                      at nextTickCallbackWith0Args (node.js:419:9)
                      at process._tickCallback (node.js:348:13)
                      at Function.Module.runMain (module.js:444:11)
                      at startup (node.js:136:18)
                  

                  我认为是因为watch任务中也没有return.错误信息也不清楚 - 至少对我来说.我尝试在最后一个 gulp.watch() 之后添加一个 return 但这也不起作用.

                  I think it is because there is also no return in the watch task. Also the error message isn't clear - at least to me. I tried adding a return after the last gulp.watch() but that didn't work either.

                  推荐答案

                  在 gulp 3.x 中,您可以像这样将任务的名称传递给 gulp.watch():

                  In gulp 3.x you could just pass the name of a task to gulp.watch() like this:

                  gulp.task('watch', function() {
                    gulp.watch('app/css/*.css', ['styles']);
                    gulp.watch('app/js/*.js', ['scripts']);
                    gulp.watch('app/img/*', ['images']);
                  });
                  

                  在 gulp 4.x 中不再是这种情况.你必须传递一个函数.在 gulp 4.x 中执行此操作的习惯方法是只使用一个任务名称传递 gulp.series() 调用.这会返回一个只执行指定任务的函数:

                  In gulp 4.x this is no longer the case. You have to pass a function. The customary way of doing this in gulp 4.x is to pass a gulp.series() invocation with only one task name. This returns a function that only executes the specified task:

                  gulp.task('watch', function() {
                    gulp.watch('app/css/*.css', gulp.series('styles'));
                    gulp.watch('app/js/*.js', gulp.series('scripts'));
                    gulp.watch('app/img/*', gulp.series('images'));
                  });
                  

                  这篇关于Gulp 错误:监视任务必须是一个函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:gulp:自动为请求添加版本号以防止浏览器缓存 下一篇:如何使用 Gulp.js 将流保存到多个目的地?

                  相关文章

                  最新文章

                      <bdo id='p7hzr'></bdo><ul id='p7hzr'></ul>

                    <tfoot id='p7hzr'></tfoot>

                    1. <legend id='p7hzr'><style id='p7hzr'><dir id='p7hzr'><q id='p7hzr'></q></dir></style></legend>

                      <small id='p7hzr'></small><noframes id='p7hzr'>

                      <i id='p7hzr'><tr id='p7hzr'><dt id='p7hzr'><q id='p7hzr'><span id='p7hzr'><b id='p7hzr'><form id='p7hzr'><ins id='p7hzr'></ins><ul id='p7hzr'></ul><sub id='p7hzr'></sub></form><legend id='p7hzr'></legend><bdo id='p7hzr'><pre id='p7hzr'><center id='p7hzr'></center></pre></bdo></b><th id='p7hzr'></th></span></q></dt></tr></i><div id='p7hzr'><tfoot id='p7hzr'></tfoot><dl id='p7hzr'><fieldset id='p7hzr'></fieldset></dl></div>