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')));
    

      

  • 相关阅读:
    【vim】分割窗口、标签页与Quickfix窗口
    新手学cocos2dx,centos7下的安装过程
    外部排序,杀鸡焉用牛刀?
    5亿整数的大文件,怎么排?
    【Hadoop】HDFS
    你好,树
    写给博客园博客团队,md的预览在哪里?
    老菜鸟致青春,程序员应该选择java 还是 c#-
    高性能server分析
    高性能服务端漫谈
  • 原文地址:https://www.cnblogs.com/carriezhao/p/10558629.html
Copyright © 2011-2022 走看看