Gulp V4.0.0 'gulp start' 不是函数 [英] Glup V4.0.0 'gulp start' is not a function

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

问题描述

我在 gulpfile.js 下面有这个.当我使用gulp start"运行应用程序时,它显示 start 不是一个函数.我正在使用的 Grup-cli 版本 V4.0.0

I have this below gulpfile.js. When i run the app using 'gulp start' then it is showing start is not a function. Glup-cli version i'm using V4.0.0

const gulp = require('gulp');
const concat = require('gulp-concat');
const browserSync = require('browser-sync').create();

const scripts = require('./scripts');
const styles = require('./styles');

// Some pointless comments for our project.

var devMode = false;

gulp.task('css', function() {
    gulp.src(styles)
        .pipe(concat('main.css'))
        .pipe(gulp.dest('dist/css'))
        .pipe(browserSync.reload({
            stream: true
        }));
});

gulp.task('js', function() {
    gulp.src(scripts)
        .pipe(concat('scripts.js'))
        .pipe(gulp.dest('./dist/js'))
        .pipe(browserSync.reload({
            stream: true
        }));
});

gulp.task('html', function() {
    return gulp.src('./src/templates/**/*.html')
        .pipe(gulp.dest('./dist/'))
        .pipe(browserSync.reload({
            stream: true
        }));
});

gulp.task('build', function() {
    gulp.start(['css', 'js', 'html'])
});

gulp.task('browser-sync', function() {
    browserSync.init(null, {
        open: false,
        server: {
            baseDir: 'dist',
        }
    });
});

gulp.task('start', function() {
    devMode = true;
    gulp.start(['build', 'browser-sync']);
    gulp.watch(['./src/css/**/*.css'], ['css']);
    gulp.watch(['./src/js/**/*.js'], ['js']);
    gulp.watch(['./src/templates/**/*.html'], ['html']);
});

推荐答案

gulp.start 在 v4 中已被弃用.根据您的需要,您可以改用 gulp.seriesgulp.parallel.

gulp.start has been deprecated in v4. Depending on your needs, you can use gulp.series or gulp.parallel instead.

- gulp.task('start', function() {
-   devMode = true;
-   gulp.start(['build', 'browser-sync']);
+ gulp.task('start', gulp.series('build', 'browser-sync'), function(done) {
+   devMode = true;
    gulp.watch(['./src/css/**/*.css'], ['css']);
    gulp.watch(['./src/js/**/*.js'], ['js']);
    gulp.watch(['./src/templates/**/*.html'], ['html']);
  });

这个问题可能与 this one 重复,但是由于该问题没有得到公认的答案,我只会回应 Mark 的答案.

This question is probably a duplicated of this one, but since that question hasn't got an accepted answer I'll just echo Mark's answer.

这篇关于Gulp V4.0.0 'gulp start' 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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