diff --git a/Makefile b/Makefile index aaa3d55..d9b9998 100644 --- a/Makefile +++ b/Makefile @@ -42,6 +42,17 @@ test-watch: test/import-*.css kill `cat test/watch.pid` # FIXME: never reached on failure rm test/watch.pid +test-watch-poll: test/import-*.css + echo '@import "import-foo.css";' > test/import-index.css + ./bin/postcss -c test/config-watch.js -w --poll & echo $$! > test/watch.pid + sleep 1 + $(DIFF) test/build/watch.css test/ref/watch-1.css + echo '@import "import-bar.css";' >> test/import-index.css + sleep 1 + $(DIFF) test/build/watch.css test/ref/watch-2.css + kill `cat test/watch.pid` # FIXME: never reached on failure + rm test/watch.pid + test-local-plugins: cd test; ../bin/postcss --use a-dummy-plugin --local-plugins -o build/local-plugins in.css diff --git a/index.js b/index.js index 20f862a..34a1b72 100644 --- a/index.js +++ b/index.js @@ -30,6 +30,10 @@ var argv = require("yargs") .describe('s', 'Alternative input syntax parser') .alias('p', 'parser') .describe('p', 'Alternative CSS parser') + .option('poll', { + describe: 'Use polling to monitor for changes.', + default: false, + }) .alias('t', 'stringifier') .describe('t', 'Alternative output stringifier') .alias('w', 'watch') @@ -146,8 +150,16 @@ async.forEach(inputFiles, compile, onError); function fsWatcher(entryPoints) { var watchedFiles = entryPoints; var index = {}; // source files by entry point + var opts = {}; + + if (argv.poll) { + opts.usePolling = true; + } + if (typeof argv.poll === 'number') { + opts.interval = argv.poll; + } - var watcher = require('chokidar').watch(watchedFiles); + var watcher = require('chokidar').watch(watchedFiles, opts); // recompile if any watched file is modified // TODO: only recompile relevant entry point watcher.on('change', function() {