【问题标题】:Task never defined: style任务从未定义:风格
【发布时间】:2020-02-23 08:59:22
【问题描述】:

我运行:npm install gulp gulp-sass gulp-autoprefixer browser-sync --save-dev

然后我在 gulpfile.js 中有这个

const gulp         = require('gulp')
const sass         = require('gulp-sass')
const autoprefixer = require('gulp-autoprefixer') 
const browserSync  = require('browser-sync').create()

function style() {
    return gulp.src(["./src/sass/main.scss"])
    .pipe(autoprefixer({
        cascade: false
    }))
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('./'))
    .pipe(browserSync.stream({ match: "**/*.css" }))
}

function watch() {
    browserSync.init({
        server: {
            baseDir: './'
        }
    })
    gulp.watch('./scss/**/*.scss', gulp.series('style'));
    gulp.watch('./*.html').on('change', browserSync.reload)
    gulp.watch('./js/**/*.js').on('change', browserSync.reload)
    gulp.watch(["./**/*.php"]).on('change', browserSync.reload)
}

gulp.task('default', gulp.parallel('style', 'watch'))


exports.style = style
exports.watch = watch

当我运行 gulp 时,我得到:Task never defined: style

这段代码有什么问题?

【问题讨论】:

  • 当您使用函数样式来定义任务时,您不需要将它们称为字符串。所以gulp.task('default', gulp.parallel(style, watch)) 是正确的。在您的watch 声明中也是如此。

标签: gulp gulp-watch gulp-sass


【解决方案1】:

试试这个

exports.style = style
exports.watch = watch
exports.default = gulp.parallel(style, watch)

【讨论】:

  • 至少参考我的评论 - 你错过了另一个错误。还有解释。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-10-25
  • 2014-08-25
  • 2021-07-23
  • 2020-12-11
  • 1970-01-01
  • 1970-01-01
  • 2019-08-11
相关资源
最近更新 更多