[英]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.