错误:使用gulp版本4时gulp.start不是函数 [英] error: gulp.start is not a function while using gulp version 4

查看:465
本文介绍了错误:使用gulp版本4时gulp.start不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用gulp的Iam CLI版本:2.2.1本地版本:4.0.2 节点版本为12.16.3 我的gulpfile.js代码是

Iam using gulp CLI version: 2.2.1 Local version: 4.0.2 The node version is 12.16.3 MY code of gulpfile.js is

 'use strict';
var gulp = require('gulp'),
sass = require('gulp-sass'),
browserSync = require('browser-sync'),
del=require('del'),
imagemin = require('gulp-imagemin'),
uglify = require('gulp-uglify'),
usemin = require('gulp-usemin'),
rev = require('gulp-rev'),
cleanCss = require('gulp-clean-css'),
flatmap = require('gulp-flatmap'),
htmlmin = require('gulp-htmlmin');

gulp.task('sass', function () {
    return gulp.src('./css/*.scss')
    .pipe(sass().on('error', sass.logError))
   .pipe(gulp.dest('./css'));
});

gulp.task('sass:watch', function () {
    gulp.watch('./css/*.scss', ['sass']);
});

gulp.task('browser-sync', function () {
 var files = [
  './*.html',
  './css/*.css',
  './img/*.{png,jpg,gif}',
  './js/*.js'
];

 browserSync.init(files, {
  server: {
     baseDir: "./"
  }
 });

});

 // Default task
gulp.task('default', gulp.series('browser-sync', function() {
  gulp.start('sass:watch');
}));
 gulp.task('clean', function() {
   return del(['dist']);
});

 gulp.task('copyfonts', function() {
   gulp.src('./node_modules/font-awesome/fonts/**/*.{ttf,woff,eof,svg}*')
  .pipe(gulp.dest('./dist/fonts'));
 });
 gulp.task('imagemin', function() {
  return gulp.src('img/*.{png,jpg,gif}')
  .pipe(imagemin({ optimizationLevel: 3, progressive: true, interlaced: true }))
  .pipe(gulp.dest('dist/img'));
 });
  gulp.task('usemin', function() {
    return gulp.src('./*.html')
   .pipe(flatmap(function(stream, file){
    return stream
     .pipe(usemin({
          css: [ rev() ],
          html: [ function() { return htmlmin({ collapseWhitespace: true })} ],
          js: [ uglify(), rev() ],
          inlinejs: [ uglify() ],
          inlinecss: [ cleanCss(), 'concat' ]
      }))
   }))
  .pipe(gulp.dest('dist/'));
 });

 gulp.task('build',gulp.series('clean', function() {
    gulp.start('copyfonts','imagemin','usemin');
 }));

在命令行上运行 gulp构建后出现的错误是:

The error I got is after running gulp build on the command line is:

  [15:38:33] Starting 'build'...
  [15:38:33] Starting 'clean'...
  [15:38:33] Finished 'clean' after 69 ms
  [15:38:33] Starting '<anonymous>'...
  [15:38:33] '<anonymous>' errored after 3.57 ms
   [15:38:33] TypeError: gulp.start is not a function
  at C:\Users\HARIKA\Desktop\bootstrapassign1\Bootstrap4\conFusion\gulpfile.js
:74:10
[15:38:33] 'build' errored after 83 m

我不知道如何解决错误.我甚至根据gulp版本4的版本将一些任务更改为gulp.series().有人可以帮助我解决该错误吗?预先谢谢你.

I dont know how to solve the erros. I even changed some of tasks to gulp.series() as per version of gulp version 4. Can anyone help me to resolve the error? Thank you in advance.

推荐答案

我遇到了同样的问题,也许找到了解决方法:

I had the same issue and perhaps found the solution:

替换以下内容:

gulp.task('sass:watch', function () {
  gulp.watch('./css/*.scss', ['sass']);

// Default task
gulp.task('default', gulp.series('browser-sync', function() {
  gulp.start('sass:watch');
}));

并添加:

gulp.task('sass:watch', function() {
  gulp.watch('./css/*.scss', gulp.series(['sass']));

// Default task
gulp.task('default', gulp.parallel('browser-sync', 'sass:watch'));

根据我的发现,您将不得不将 gulp.series gulp.parallel 与gulp + 4.x交替使用.

From what I have found you will have to use gulp.series and gulp.parallel interchangeably with gulp +4.x

现在进行第二部分更改:

Now for the second part change:

gulp.task('copyfonts', function() {
  gulp.src('./node_modules/font-awesome/fonts/**/*.{ttf,woff,eof,svg}*')
  .pipe(gulp.dest('./dist/fonts'));
});

在此处添加返回:

gulp.task('copyfonts', function() {
  return gulp.src('./node_modules/font-awesome/fonts/**/*.{ttf,woff,eof,svg}*')
  .pipe(gulp.dest('./dist/fonts'));
});

就像上一个答案中所示,完成最后一个任务:

And like shown in the previous answer make the last task:

gulp.task('build', gulp.series('clean','copyfonts','imagemin','usemin'));

希望这会有所帮助!

这篇关于错误:使用gulp版本4时gulp.start不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆