简体   繁体   English

gulp-watch-less不会在Windows上触发

[英]gulp-watch-less not triggering on Windows

I have been trying to solve this problem for a couple of days now. 我已经尝试解决这一问题已有几天了。 I am trying to get gulp to compile my less files when I save them but gulp-watch-less is not being triggered by changes in files I am watching. 我试图使gulp在保存它们时编译较少的文件,但是没有gulp-watch-less不会被我正在观看的文件的更改触发。 My gulpfile.js is: 我的gulpfile.js是:

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

gulp.task('default', function () {
    return gulp.src('less/style.less')
        .pipe(watchLess('less/style.less'))
        .pipe(less())
        .pipe(gulp.dest('css'));
});

/*
gulp.task('watch', function() {
   // Watch less files
  gulp.watch('less/style.less', ['less']);
 });

 gulp.task('less', function() {
    return gulp.src('src/scss/style.scss')
        .pipe(less())
        .pipe(gulp.dest('css'));
});

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

When I run gulp initially it will generate a new css file, but after that any changes I make to style.less are not triggering the new file update. 最初运行gulp时,它将生成一个新的CSS文件,但是之后,我对style.less所做的任何更改都不会触发新文件的更新。 When I do make changes the console does show: 当我进行更改时,控制台会显示:

LESS saw style.less was changed 较少看到style.less被更改

But the new file is not generated. 但是不会生成新文件。 I tried to follow solutions at Gulp suddenly not working anymore after npm update #800 . 在npm update#800之后,我试图遵循Gulp的解决方案突然不起作用了 I have re-installed nodejs twice already to try and get this to work without success. 我已经重新安装了nodejs两次,尝试使其成功运行。

I managed to solve this by using gulp-watch in place of gulp-watch-less. 我设法通过使用gulp-watch来代替gulp-watch-less来解决此问题。 My new gulpfile.js is: 我的新gulpfile.js是:

var gulp = require('gulp');
//var watchLess = require('gulp-watch-less');
var watch = require('gulp-watch');
var less = require('gulp-less');
/*
gulp.task('default', function () {
    return gulp.src('less/style.less')
        .pipe(watchLess('less/style.less'))
        .pipe(less())
        .pipe(gulp.dest('css'));
});
*/

gulp.task('watch', function() {
   // Watch less files
  watch('less/style.less', function() {
    gulp.start('less');
    });
 });

 gulp.task('less', function() {
    return gulp.src('less/style.less')
        .pipe(less())
        .pipe(gulp.dest('css'));
});

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

There does seem to be a problem with using gulp-watch-less on Windows that is not triggering tasks when files are altered. 在Windows上使用无牙胶手表似乎确实存在问题,该问题在文件更改时不会触发任务。

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

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