错误:gulp.start不是使用gulp版本4时的函数

ws51t4hk  于 2022-12-08  发布在  Gulp
关注(0)|答案(2)|浏览(224)

Iam使用gulpCLI版本:2.2.1本地版本:4.0.2****节点版本为12.16.3gulpfile.js的MY代码为

'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 build后,我得到的错误是:

[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.series()作为每个版本的gulp版本4。有人能帮助我解决错误吗?提前谢谢你。

s5a0g9ez

s5a0g9ez1#

替换这两个任务:

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

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

与:

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

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

gulp.start不是gulp 4+的一部分-它是在v3中,虽然即使在那里也没有真正批准使用。

2o7dmzc5

2o7dmzc52#

我遇到了同样的问题,也许找到了解决办法:
替换以下内容:

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.seriesgulp.parallel与gulp +4.x互换使用
现在进行第二部分修改:

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

在此处添加return

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

并像前面所示的那样做出最后一个任务的回答:

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

希望这对你有帮助!

相关问题