简体   繁体   中英

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.

 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

The gulp.watch function requires a list of files and a function as second parameter.

You have to generate the function either with gulp.parallel or gulp.series , such as in your case:

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:

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'))
});    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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