Gulp wouldn't watch any changes

自古美人都是妖i 提交于 2019-12-02 14:29:35

问题


I am scratching my head around but can't seem to figure out whats wrong with the following gulpfile which simply watch and compile less file.

This simply won't watch less changes, I have tried all gulp, gulp watch. I have to manually run gulp after each change to compile them. Is there something wrong that causing watch to not work as expected?

Gulp Version CLI version 1.4.0 Local version 3.9.1

NPM 4.1.2 Node v7.7.2

var gulp = require('gulp');

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

// gulp compile paths

var paths = {
    dist: 'assets/dist'
};

gulp.task('css', function() {
    return gulp.src('assets/less/styles.less')
        .pipe(less({
            compress: true
        }))
        .pipe(gulp.dest(paths.dist))
});

gulp.task('watch', function() {
    gulp.watch('assets/less/*.less', ['css']);  // Watch all the .less files, then run the less task
});

gulp.task('default', ['watch']);

回答1:


Make sure you have correct path to the .less files also you need to add bowersync.reload for it to work.

gulp.task('watch', function () {
    gulp.watch('assets/less/*.less', ['css']);
    // init server
    browserSync.init({
        server: {
            proxy: "local.build",
            baseDir: appPath.root
        }
    });

    gulp.watch([appPath.root + '**'], browserSync.reload);
});

gulp.task('default', ['watch']);


来源:https://stackoverflow.com/questions/49416905/gulp-wouldnt-watch-any-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!