Gulp only compiles LESS the first time I run it. It still sees my changes but doesn't update the compiled CSS file

夙愿已清 提交于 2020-01-16 13:23:39

问题


I'm a little new with gulp. I have an old Wordpress theme which I'm trying to use gulp with to compile the LESS files. My structure is like this:

-theme
--library
---less
----style.less (all the imports all of the less files)
----brew (all the less files are in this folder)
---css
----style.css (this is the compiled css file)
-gulp-dev
--node_modules
--gulpfile.js
--package.json

And here is my gulpfile:

var gulp = require('gulp');
var less = require('gulp-less'); 
var browserSync = require('browser-sync').create();
var reload      = browserSync.reload;


/* Task to compile less */
gulp.task('compile-less', function() {  
  gulp.src('../theme/library/less/style.less')
    .pipe(less())
    .pipe(gulp.dest('../theme/library/css/'));
}); 
/* Task to watch less changes */
gulp.task('watch-less', function() {  
  gulp.watch('../theme/library/less/**/*.less' , ['compile-less']);
});

gulp.task('serve', function () {

    // Serve files from the root of this project
    browserSync.init({ 
      open: 'external',
      proxy: 'wordpress.localhost:8080',
      port: 8080
    }); 
    gulp.watch('../theme/library/less/**/*.less').on("change", reload);
});

/* Task when running `gulp` from terminal */
gulp.task('default', ['watch-less', 'serve']);

This seems to work fine. I run gulp and it launches Browsersync and starts watching my LESS files. I make a change to one of the LESS files, it tracks the change and compiles, and the change shows up on the local website. Everything works fine. The problem is, the next time I make a change and save it, gulp tells me that is saw the save and compiled the file again, but the changes don't appear in the file. Nothing in style.css changes after I've made that first change. If I close out gulp then run it again, it compiles the LESS changed the first time but then doesn't do it again.

If I open the compiled css file in sublimetext, I can see it refresh when it recompiles... but the changes just don't show up.

Any ideas what is going on here?

来源:https://stackoverflow.com/questions/49618710/gulp-only-compiles-less-the-first-time-i-run-it-it-still-sees-my-changes-but-do

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