简体   繁体   English

如何使“ gulp watch”命令起作用?

[英]How can I make 'gulp watch' command work?

Browser console doesn't watch errors but when I try to run the command in git console I have got a error. 浏览器控制台不会监视错误,但是当我尝试在git console中运行命令时出现错误。

 let gulp = require('gulp'); let sass = require('gulp-sass'); let watch = require('gulp-watch'); let browserSync = require('browser-sync'); gulp.task('sass', function() { return gulp.src('src/scss/index.scss') .pipe(sass().on('error', sass.logError)) .pipe(gulp.dest('src/css/index.css')) }); gulp.task('sass:watch', function() { gulp.watch('src/scss/index.scss', ['sass']); }); gulp.task('browser-sync', function() { browserSync({ server: { baseDir: 'src' }, notify: false }); }); 

Link to my repository https://github.com/dzhulay/Step-Ham 链接到我的存储库https://github.com/dzhulay/Step-Ham

The gulp.watch function requires a list of files and a function as second parameter. gulp.watch函数需要一个文件列表和一个函数作为第二个参数。

You have to generate the function either with gulp.parallel or gulp.series , such as in your case: 您必须使用gulp.parallelgulp.series生成函数,例如您的情况:

gulp.task('watch', function() {
    gulp.watch('src/scss/index.scss', gulp.series('sass'));
});

Also, in order to avoid the "file exists" error as specified in your comment, please implement "gulp-chmod" in your sass task, such as: 另外,为了避免注释中指定的“文件存在”错误,请在您的sass任务中实现“ gulp-chmod”,例如:

var chmod = require('gulp-chmod');

gulp.task('sass', function() {
return gulp.src('src/scss/index.scss')
    .pipe(chmod(0o755))
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('src/css/index.css'))
});    

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM