Glup V4.0.0 'gulp start' is not a function

前端 未结 2 434
梦毁少年i
梦毁少年i 2021-01-11 15:45

I have this below gulpfile.js. When i run the app using \'gulp start\' then it is showing start is not a function. Glup-cli version i\'m using V4.0.0

const g         


        
相关标签:
2条回答
  • 2021-01-11 16:29

    gulp.start has been deprecated in v4. Depending on your needs, you can use gulp.series or gulp.parallel instead.

    - gulp.task('start', function() {
    -   devMode = true;
    -   gulp.start(['build', 'browser-sync']);
    + gulp.task('start', gulp.series('build', 'browser-sync'), function(done) {
    +   devMode = true;
        gulp.watch(['./src/css/**/*.css'], ['css']);
        gulp.watch(['./src/js/**/*.js'], ['js']);
        gulp.watch(['./src/templates/**/*.html'], ['html']);
      });
    

    This question is probably a duplicated of this one, but since that question hasn't got an accepted answer I'll just echo Mark's answer.

    0 讨论(0)
  • 2021-01-11 16:32

    As Derek said, in v4 of gulp you have to use gulp.series or gulp.parallel;

    Another differences for v4 is that you need to explicit when the task is done, you have 6 ways to do it.. I'll link this answer for a really good explanation Gulp error: The following tasks did not complete: Did you forget to signal async completion?

    Mohamed explanation might be useful to understand in depth the reasons, you can find both: Migrate gulp.start function to Gulp v4

    I have tried the solution but it needed more code, so I will write my main changes here:

    gulp.task("build",
        gulp.series(gulp.parallel("css", "js", "html"), function (done) {
            done();
        })
    );
    
    
      gulp.task("start", gulp.series("build", "browser-sync"), function (done) {
          devMode = true;
          gulp.watch(["./src/css/**/*.css'"], ["css"]);
          gulp.watch(["./src/js/**/*.js"], ["js"]);
          gulp.watch(["./src/templates/**/*.html"], ["html"]);
       done();
    });
    

    in all of the other task, I simply added the done() function ( with the exception of the task html because it has a return that already explicit when the task is done)

    Hope this will help someone else, have a nice day :)

    0 讨论(0)
提交回复
热议问题