zoukankan      html  css  js  c++  java
  • gulp4小demo

    本来想着用gulp搭建一个自动化构建工具,结果一顿报错,后来发现我重新安装的gulp版本是4.0.0,与3版本还是不太一样的,遂记之。

    Gulp 3版本Demo:

    const gulp = require('gulp');
    
    // 设定一个任务
    gulp.task('hello',() => {
        console.log('print hello');
    });
    
    // 再设定一个任务
    gulp.task('world',() => {
        console.log('print world');
    });
    
    // 设置一个默认的任务
    gulp.task('default',['hello','world']);
    

      但用上述语句在Gulp4中会报错:

    assert.js:350
        throw err;
        ^
    
    AssertionError [ERR_ASSERTION]: Task function must be specified
        at Gulp.set [as _setTask] (C:UserszxqDesktopgulpCourse
    ode_modules\_undertaker@1.2.0@undertakerlibset-task.js:10:3)
        at Gulp.task (C:UserszxqDesktopgulpCourse
    ode_modules\_undertaker@1.2.0@undertakerlib	ask.js:13:8)
        at Object.<anonymous> (C:UserszxqDesktopgulpCoursegulpfile.js:26:6)
        at Module._compile (internal/modules/cjs/loader.js:688:30)
        at Object.Module._extensions..js (internal/modules/cjs/loader.js:699:10)
        at Module.load (internal/modules/cjs/loader.js:598:32)
        at tryModuleLoad (internal/modules/cjs/loader.js:537:12)
        at Function.Module._load (internal/modules/cjs/loader.js:529:3)
        at Module.require (internal/modules/cjs/loader.js:636:17)
        at require (internal/modules/cjs/helpers.js:20:18)
    

      Gulp 4中的正确写法(结合async 和 await):

    const gulp = require('gulp');
    
    gulp.task('hello', async() => {
        await console.log('print hello');
    });
    
    gulp.task('world', async() => {
        await console.log('print world');
    });
    
    gulp.task('default',gulp.series(gulp.parallel('hello','world')));
    

      

  • 相关阅读:
    Java类、实例初始化的顺序
    Java中堆栈的区别
    int与Integer的区别(基本类型与复杂类型的对比)转
    JS中函数执行顺序的问题?
    springMVC --@RequestParam注解(后台控制器获取参数)
    如何安装request库
    流程图
    认识broken pipe
    postman动态使用url
    自定义一个List排序规则,然后对另一个List按照该规则排序
  • 原文地址:https://www.cnblogs.com/carriezhao/p/10558629.html
Copyright © 2011-2022 走看看