1 | function WatchIgnorePlugin(paths) {
|
2 | this.paths = paths;
|
3 | }
|
4 |
|
5 | module.exports = WatchIgnorePlugin;
|
6 |
|
7 | WatchIgnorePlugin.prototype.apply = function (compiler) {
|
8 | compiler.plugin("after-environment", function () {
|
9 | compiler.watchFileSystem = new IgnoringWatchFileSystem(compiler.watchFileSystem, this.paths);
|
10 | }.bind(this));
|
11 | };
|
12 |
|
13 | function IgnoringWatchFileSystem(wfs, paths) {
|
14 | this.wfs = wfs;
|
15 | this.paths = paths;
|
16 | }
|
17 |
|
18 | IgnoringWatchFileSystem.prototype.watch = function (files, dirs, missing, startTime, delay, callback, callbackUndelayed) {
|
19 | var ignored = function (path) {
|
20 | return this.paths.some(function (p) {
|
21 | return ((p instanceof RegExp) ? p.test(path) : path.indexOf(p) === 0);
|
22 | });
|
23 | }.bind(this);
|
24 |
|
25 | var notIgnored = function (path) { return !ignored(path); };
|
26 | var ignoredFiles = files.filter(ignored);
|
27 | var ignoredDirs = dirs.filter(ignored);
|
28 |
|
29 | this.wfs.watch(files.filter(notIgnored), dirs.filter(notIgnored), missing, startTime, delay, function (err, filesModified, dirsModified, fileTimestamps, dirTimestamps) {
|
30 | if(err) return callback(err);
|
31 |
|
32 | ignoredFiles.forEach(function (path) {
|
33 | fileTimestamps[path] = 1;
|
34 | });
|
35 |
|
36 | ignoredDirs.forEach(function (path) {
|
37 | dirTimestamps[path] = 1;
|
38 | });
|
39 |
|
40 | callback(err, filesModified, dirsModified, fileTimestamps, dirTimestamps);
|
41 | }, callbackUndelayed);
|
42 | };
|