问题
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