-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Files changed by tasks stared by watch with nospawn on do not trigger new events #231
Comments
I'll take a look... but why do you need |
For performance reasons mainly. With |
I can confirm this. With spawn:false somehow if "livereload" task watches a location being changed by another task then the change doesn't get noticed by "livereload". |
Actually, I have found a pretty neat workaround: start another grunt process with a specific --gruntfile that handles only LiveReload. Since I compile everyhing to pure-html&css&js app in a separate /build directory I don't need a lot of LR configuration. Also it solves the problem of grunt-LR tasks waiting for others to finish, because in the other process the filesystem change is noticed immediately, IMHO. |
@tillda I love your workaround. |
I'm having the same problem:
watch:
options:
livereload: false
# spawn: false
build_files:
files: [ '<%= build_dir %>/**/*.css' ]
options:
livereload: true
sass_files:
files: [ 'src/**/*.{sass,scss}' ]
tasks: [ 'compass' ]
source_files:
files: [ 'src/**/*.{sass,scss}' ]
tasks: [ 'copy:source_files' ] Example is shortened, but shows the problem. @shama @tillda @iclanzan |
@gonsfx I don't know. I made a tool for managing a development processes that run in background: https://github.com/tillda/pm.js |
In my example, the livereload of the compiled .css is triggered on every second save of the .sass file. @shama Seems i can work around this by setting the interval option to 1 - which seems awkward. Does gaze use fs.watchFile (requiring an interval) instead of fs.watch? |
This happens because Grunt only runs one task at a time. With Gaze uses a combination of So if setting interval to 1 works for you, that's fine. It would likely heat up the CPU for users with larger file sets though. So just be careful with such a low interval. |
Its not a solution i'd really like to use, was just pointing it out in case it might help solving the problem. I was digging around in the code of this and gaze for a few hours today, but i neither found the exact reason for this behavior nor a feasible solution to fix it. After reading your latest comment - shouldn't it be possible to run the queue and the watch task itself in two different processes? If i can somehow help you out with this, drop me a note. |
That is what I'm experimenting now with preemptively forking a grunt process that waits to be triggered: https://github.com/shama/wait-grunt This should speed up the perceived spawn time but doesn't help much with the context issue. As we only get a channel to send data between processes. |
Complete duct tape solution: module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
var WATCH_TASK = 'watch';
var watchConfig;
if (process.argv.indexOf(WATCH_TASK) === -1) {
grunt.util.spawn({
grunt: true,
args: [WATCH_TASK]
});
watchConfig = {
options: {
livereload: false,
spawn: false
},
// tasks to produce target files
};
} else {
watchConfig = {
options: {
spawn: false
},
livereload: {
files: [
// target files to watch
]
}
};
}
grunt.initConfig({
watch: watchConfig
// other tasks
});
} |
@princed 👍 for your solution. But this does not work when there are multiple watch tasks to be run in parallel along with some other blocking tasks like compass:watch using grunt-concurrent. After trying for a while, I could figure out a way, that might come helpful to others, who are trying to achieve the same I wanted. Below is a sample working configuration: var compassConfig = {
options: {
config: 'config.rb',
bundleExec: true
},
compile: {
options: {
force: true
}
},
watch: {
options: {
watch: true,
force: true
}
}
};
var copyConfig = {
src: {
cwd: './',
src: ['src/**/*', '!src/sass/**/*'],
dest: 'dist/',
expand: true
}
}
var watchConfig = {
options: {
livereload: false,
spawn: false
},
livereload: {
files: ['dist/**/*'],
options: {
livereload: true,
spawn: false
}
},
src: {
files: ['src/**/*', '!src/sass/**/*'],
tasks: ['copy:src'],
}
};
var connectConfig = {
options: {
base: 'dist/',
middleware: function(connect, options, middlewares) {
options.base = String(options.base);
var express = require('express');
var app = express();
var directory = require('serve-index');
app.use(express.static(options.base));
app.get('/', function(req, res) {
return res.render("" + options.base + "/index.html");
});
app.use(directory(options.base));
middlewares.unshift(app);
return middlewares;
},
port: 3333
},
dev: {
options: {
open: true,
livereload: true,
}
}
}
};
var concurrentConfig = {
watch: {
tasks: ['compass:watch', 'connect_watch', 'watch:src'],
options: {
logConcurrentOutput: true
}
}
};
grunt.initConfig({
compass: compassConfig,
concurrent: concurrentConfig,
connect: connectConfig,
copy: copyConfig,
watch: watchConfig
});
grunt.registerTask('connect_watch', ['connect:dev', 'watch:livereload']);
grunt.registerTask('default', ['compass:compile', 'concurrent:watch']);
|
If we take this example from the docs, which runs fine:
and add the
nospawn: true
option, thelivereload
target will never be called even thoughsass
changes files.Any thoughts on this?
The text was updated successfully, but these errors were encountered: