-
Notifications
You must be signed in to change notification settings - Fork 135
watching files doesn't work #317
Comments
Hi Andrej, I'm planning to do a general refactoring of the gulp tasks with Edit: accidentally closed it. |
Hey Jonathan, thanks for the explanations, let's wait for gulp 4.0 :) |
Hi, First of all thank's a ton for this generator. Big shout out to all the contributors. Well speaking on the issue, yes race condition is happening when ever i modify only SCSS file. Flow:
Culprit code for race bug in the above flow:(File - watching.js) var watchFiles = paths.jsFiles
.concat([
'app/index.html',
'.tmp/*/styles/*.css', /* This line creates a race condtion*/
'app/*/assets/**/*'
])
.concat(paths.templates); Explaination: This is piece of code is triggering a watch task for Solution/FixComment this code Question to AuthorI am curious to know why a watch for Can i create a pull request to fix the issue? Hope this helps solving this issue. Keep up the good work. Appreciate the effort. |
Hi @nirus, thanks for your valuable input. .tmp//styles/.css is necessaryWatching // WON'T WORK
gulp.watch('app/*/styles/**/*.scss', ['styles'], function () {
bs.reload();
}); AlternativeHowever deleting the css shouldn't cause the any other tasks to start. So I came up with this version of the watch tasks that watches for css changes separately and only triggers a browser reload. Can some of you verify if this helps? If so, I'll include it in the next release, maybe even publish a bugfix version.
// WATCH
gulp.task('watch', ['inject-all'], function () {
// browser sync server
bsInit(['app', '.tmp']);
var watchFiles = paths.jsFiles
.concat([
'app/index.html',
'app/*/assets/**/*'
])
.concat(paths.templates);
// start linting and watching
gulp.start('linting');
gulp.watch(watchFiles, function (event) {
console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
if (event.type === 'changed') {
bs.reload();
gulp.start('linting');
}
else { // added or deleted
// inject in index (implicitly reloads)
gulp.start('inject-all');
}
});
// watch for changes in scss
gulp.watch('app/*/styles/**/*.scss', ['styles']);
// watch for changes in css
gulp.watch('.tmp/*/styles/*.css', function () {
bs.reload();
});
// watch for changes in environment files and new config files
gulp.watch([
'app/main/constants/env-*.json',
'app/*/constants/*config-const.js'
], ['environment']);
}); Please, let me know if this works for you! |
I have tested this and it seems to work! Thanks. |
for future reference, this could prevent multiple browser reloads, when css watch is triggered with multiple modules: // watch for changes in css
gulp.watch('.tmp/*/styles/*.css', (function () {
var last = 0;
var tolerance = 15; // don't retrigger within this tolerance
var lastTimeout;
return function () {
var now = new Date().getTime();
var delta = now - last;
if (delta < tolerance) {
clearTimeout(lastTimeout);
}
last = now;
lastTimeout = setTimeout(function () {
bs.reload();
}, tolerance);
};
})()); |
Hi there,
I would like to open a discussion regarding the gulp watch functionality.
I think that watching temporary files doesn't make sense and it brings more issues. Even a simple change of scss files might cause loosing injected css files so after some changes you need to stop and run gulp watch again.
Image if you change a scss file you would expect that
0. sass file is modified
In fact the watching function triggers this weird loop:
0. sass file is modified
Is you can see there are same race conditions that might cause some unpredictable behaviour as we can see in #223
It seems to me that this is related to #129
I think the easiest way is to watch only source files (sass, jade what so ever) and if there is a need to inject them, the injection should be done in the corresponding task like
styles
. This will reduce race conditions. Also cleaning should be done more carefully. E.g. we should clean only files related to a change not to all of it.What do you think? Do you see any problems with this approach?
Best regards,
Andrej
The text was updated successfully, but these errors were encountered: