【问题标题】:Gulp JS task never defined defaultGulp JS 任务从未定义默认值
【发布时间】:2021-07-23 13:19:27
【问题描述】:

我正在这里做一个 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 错误。

知道我在这里缺少什么以及如何解决这个问题吗?

【问题讨论】:

    标签: javascript node.js sass gulp


    【解决方案1】:

    您需要导出默认值 (exports.default = FUNCTION) 并将其指向您想要的默认函数(编译/监视),或者您需要像 gulp compile/gulp watch 一样运行 gulp。

    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;
    

    【讨论】:

    • 你能编辑我上面的代码并告诉我确切的位置吗?对不起,我是初学者。
    • 好的,没问题。我稍后会添加它。
    • 请做。我只是想在运行时同时运行这两个函数
    猜你喜欢
    • 2021-10-25
    • 1970-01-01
    • 2019-09-20
    • 2017-07-11
    • 1970-01-01
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多