简体   繁体   English

Gulp 4错误:“您是否忘记了异步完成信号?”

[英]Gulp 4 error: “Did you forget to signal async completion?”

I am working on a small project that needs .sass files compiled into .css files. 我正在一个需要将.sass文件编译成.css文件的小项目。 I have used Gulp a while ago and loved it, but my old gulpfile.js does not work anymore, because Gulp has changed since version 4. 我曾经使用过Gulp并喜欢它,但是我的旧gulpfile.js不再起作用,因为Gulp自版本4以来已更改。

I have made a new gulpfile.js : 我做了一个新的gulpfile.js

var gulp    = require('gulp'),
    sass    = require('gulp-sass'),
    rename  = require('gulp-rename');

var paths = {
  styles: {
    src: 'src/scss/*.scss',
    dest: 'build/css'
  }
};

function styles() {
  return gulp
    .src(paths.styles.src, {
      sourcemaps: true
    })
    .pipe(sass())
    .pipe(rename({
      basename: 'main',
      suffix: '.min'
    }))
.pipe(gulp.dest(paths.styles.dest));
}

function watch() {
  gulp
    .watch(paths.styles.src, styles);
}

var syncConfig = {
    server: {
      baseDir   : './',
      index     : 'index.html'
    },
    port        : 3000,
    open        : false
  };

  // browser-sync
  function server() {
    init(syncConfig);
  }

var build = gulp.parallel(styles, watch, server);

gulp
  .task(build);
gulp
  .task('default', build);

I have a "Did you forget to signal async completion?" 我有一个“您是否忘记了异步完成信号?” error returned by the console. 控制台返回的错误。

Where is my mistake? 我的错误在哪里?

There ware two things missing: the browsersync variable browsersync = require('browser-sync').create() and the callback for the server function: 这里缺少两件事:browsersync变量browsersync = require('browser-sync').create()和服务器函数的回调:

function server(done) {
  if (browsersync) browsersync.init(syncConfig);
  done();
}

It compiles SASS to CSS, still there is this problem: the page does not reload automatically when changes are made in the main.scss . 它将SASS编译为CSS,仍然存在此问题:在main.scss中进行更改时,页面不会自动重新加载

Here is the entire code: 这是完整的代码:

var gulp    = require('gulp'),
    browsersync = require('browser-sync').create(),
    sass    = require('gulp-sass'),
    rename  = require('gulp-rename');

var paths = {
  styles: {
    src: 'src/scss/*.scss',
    dest: 'build/css'
  }
};

function styles() {
  return gulp
    .src(paths.styles.src, {
      sourcemaps: true
    })
    .pipe(sass())
    .pipe(rename({
      basename: 'main',
      suffix: '.min'
    }))
.pipe(gulp.dest(paths.styles.dest));
}

function watch() {
  gulp
    .watch(paths.styles.src, styles);
}

var syncConfig = {
    server: {
      baseDir   : './',
      index     : 'index.html'
    },
    port        : 3000,
    open        : false
  };

// browser-sync
function server(done) {
  if (browsersync) browsersync.init(syncConfig);
  done();
}

var build = gulp.parallel(styles, watch, server);

gulp
  .task(build);
gulp
  .task('default', build);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Gulp:您是否忘记发出异步完成错误信号 - Gulp: Did you forget to signal async completion error Gulp 错误:“以下任务未完成;您是否忘记发出异步完成信号” - Gulp Error: "The following tasks did not complete; Did you forget to signal async completion" 我如何解决此错误'以下任务未完成:默认,您是否忘记了异步完成信号? ' - how can i solve this error 'The following tasks did not complete: default, Did you forget to signal async completion? ' Gulp 4 Sass忘记信号异步完成 - Gulp 4 sass forget to signal async completion Gulp和Babel-信号异步完成错误 - Gulp and Babel - signal async completion error 升级到Gulp 4时发出异步完成警告警告 - Signal async completion warning upon upgrade to Gulp 4 使用Gulp,Babel和config.yml信号异步完成 - Signal async completion with Gulp, Babel and config.yml nodejs 与 supertest,为不同的测试用例调用一个端点两次得到一个你忘记在测试中等待异步的东西吗? - nodejs with supertest, calling an endpoint twice for different test cases getting a Did you forget to wait for something async in your test? 错误:找不到npm模块“流星/会话”。 您是否忘了在“模块运行时”包中的package.js中调用“ Npm.depends”? - Error: Can't find npm module 'meteor/session'. Did you forget to call 'Npm.depends' in package.js within the 'modules-runtime' package? GraphQL - POST 主体丢失。 你忘了使用 body-parser 中间件吗? - GraphQL - POST body missing. Did you forget use body-parser middleware?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM