Gulp JS任务从未定义默认值

thtygnil  于 2022-12-08  发布在  Gulp
关注(0)|答案(1)|浏览(156)

我在这里做一个GuLP JS项目。
在我的gulpfile.js里:

const gulp = require("gulp");
const sass = require("gulp-sass");
const browserSync = require("browser-sync").create();

function compile() {
  return gulp
    .src("app/scss/*.scss")
    .pipe(sass())
    .pipe(gulp.dest("app/css"))
    .pipe(browserSync.stream());
}

// Watch for changes
function watch() {
  browserSync.init({
    server: "./app/",
    index: "./index.html",
  });

  gulp.watch("app/scss/*.scss", style);
  gulp.watch("./*.html").on("change", browserSync.reload);
  gulp.watch("./js/*.js").on("change", browserSync.reload);
}

exports.compile = compile;
exports.watch = watch;

当我在终端上运行gulp时,它返回一个Task never defined Default错误。
你知道我错过了什么吗?我该怎么弥补?

uyto3xhc

uyto3xhc1#

您需要导出default(exports.default = FUNCTION)并将其指向您想要的默认函数(compile/watch),或者您需要运行您的gulp,如gulp compile/gulp watch

const gulp = require("gulp");
const sass = require("gulp-sass");
const browserSync = require("browser-sync").create();

function compile() {
  return gulp
    .src("app/scss/*.scss")
    .pipe(sass())
    .pipe(gulp.dest("app/css"))
    .pipe(browserSync.stream());
}

// Watch for changes
function watch() {
  browserSync.init({
    server: "./app/",
    index: "./index.html",
  });

  gulp.watch("app/scss/*.scss", style);
  gulp.watch("./*.html").on("change", browserSync.reload);
  gulp.watch("./js/*.js").on("change", browserSync.reload);
}

exports.compile = compile;
exports.watch = watch;
exports.default = compile;

相关问题