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:\Users\zxq\Desktop\gulpCourse\node_modules\_undertaker@1.2.0@undertaker\lib\set-task.js:10:3)
    at Gulp.task (C:\Users\zxq\Desktop\gulpCourse\node_modules\_undertaker@1.2.0@undertaker\lib\task.js:13:8)
    at Object.<anonymous> (C:\Users\zxq\Desktop\gulpCourse\gulpfile.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')));

  

转载于:https://www.cnblogs.com/carriezhao/p/10558629.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值