-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Exposing watch in API #1056
Comments
I would also like a way to use the watch functionality through an API. This has the big advantage that external build tools are not necessary if you want to have a callback when a file is compiled. |
I think we should expose this. Maybe one day we will be able to tell libsass which files need to be reloaded individually. |
Agree, and I'd be willing to add hooks into grunt-sass once this is done. |
+1 would like this functionality. |
Any progress on this? It would be really nice to have this as part of Gulp/Grunt process. |
+1 a good example of implementation is webpack: var webpack = require("webpack");
// returns a Compiler instance
var compiler = webpack({
// configuration
});
// regular build
compiler.run(function(err, stats) {
// ...
});
// build + watch
compiler.watch({ // watch options:
aggregateTimeout: 300, // wait so long for more changes
poll: true // use polling instead of native watchers
// pass a number to set the polling interval
}, function(err, stats) {
// ...
}); |
@saper I would like to try to tackle this issue. Do you have any advice on how to do it? I tried to look at the way render works, but it seems that the way it works in the cli and the way it is done in Thanks. |
There is a proposal in #1156 to split CLI as the separate module and I think this is a good way to fix our hopelessly broken command line interface (in a incompatibly way I hope). This way CLI could depend on the watcher (whichever one is about to be chosen) and the dependency calculator (currently https://github.com/xzyfer/sass-graph). For now we have disabled CLI watcher tests, because they were not working. Maybe trying to expose the API and use that in tests would be a good place to start. See #1288 #1261 #1260 #1216. Calling a watcher is actually a line or two in our CLI so it might be not that difficult. |
lib/watcher.js is already a progress, but the way it is called from node-sass binary needs to be refactored |
FYI sass/sass#2823 now exists to discuss this in a cross-implementation context. |
+1 |
I've read through the issues about the
--watch
flag and appreciate the amount of effort that has been put into maintaining it! 😄 The implementation is impressively terse and as I understand it (the PR mentioning this was merged), has recently been overhauled.Would it be possible to expose this in the Node API so that it could be invoked programmatically (from a task runner like Gulp or Grunt, or just in plain Node) through something like
sass.watch('./file.scss')
?In the case of task runners, this could allow allow for an evented API that allows for additional build steps on recompile. Perhaps something like this:
If this sounds reasonable, I could get started on a PR for it. Otherwise, I plan on creating a npm module for this.
The text was updated successfully, but these errors were encountered: