如何解决如何自动运行所有gulp任务?
我来找你。 我正在使用gulp和browser-sync来自动化我的任务:编译sass,在每次更改时重新启动开发服务器,并检查浏览器中的更改。我只是想使其更快。问题是当我运行gulp(我也使用gulp-nodemon)时,它只运行nodemon,但浏览器同步未运行,其他任务也未运行。如果我分别运行每个任务,它们将起作用,但是默认情况下,与gulp一起运行时,它们将不起作用。如果您想帮助我,我将永远感激您。
这是我的代码
const gulp = require('gulp'),sass = require('gulp-sass'),autoprefixer = require('gulp-autoprefixer'),browserSync = require('browser-sync').create(),nodemon = require('gulp-nodemon'),watch = require('gulp-watch');
gulp.task('scss',() => {
let stream = gulp
.src('./src/scss/*/*.scss')
.pipe(sass({outputStyle: 'expanded',}))
.pipe(autoprefixer({ versions: 'last 2 browsers',}))
.pipe(gulp.dest('./src/public/css'))
.pipe(browserSync.stream());
return stream;
});
gulp.task('nodemon',cb => {
let started = false;
return nodemon({
script: './src/index.js',ext: 'ejs js',ignore: ['gulpfile.js'],}).on('start',() => {
if (!started) {
cb();
started = true;
}
});
});
gulp.task('browser-sync',gulp.series('nodemon'),() => {
browserSync.init({
proxy: 'http://localhost:3000',open: false,files: ['public/**/*.js'],browser: 'google chrome',port: 3000,});
});
gulp.task('default',gulp.series('browser-sync'),() => {
gulp.watch('./src/views/*/*.ejs').on('change',browserSync.reload());
gulp.watch('./src/public/*/*.js').on('change',browserSync.reload());
gulp.watch('./src/public/css/*/*.css').on('change',browserSync.stream());
gulp.watch('./src/scss/*/*.scss',gulp.series('scss'));
});
解决方法
这有三个参数:
gulp.task('browser-sync',gulp.series('nodemon'),() => {
在gulp v4 +中,您只能有两个参数,因此请将其更改为
gulp.task('browser-sync',gulp.series('nodemon',() => {
并与
相同 gulp.task('default',gulp.series('browser-sync',() => {
- 还会有一个封闭的括号
)
,也要添加到这些函数的末尾,例如}));
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。