forked from external-repos/squoosh
Use classes for webpack plugins.
This commit is contained in:
@@ -1,23 +1,23 @@
|
|||||||
let fs = require('fs');
|
const fs = require('fs');
|
||||||
|
|
||||||
module.exports = WatchTimestampsPlugin;
|
module.exports = class WatchTimestampsPlugin {
|
||||||
|
constructor(patterns) {
|
||||||
|
this.patterns = patterns;
|
||||||
|
}
|
||||||
|
|
||||||
function WatchTimestampsPlugin(patterns) {
|
apply(compiler) {
|
||||||
this.patterns = patterns;
|
compiler.plugin('watch-run', (watch, callback) => {
|
||||||
}
|
let patterns = this.patterns;
|
||||||
|
let timestamps = watch.fileTimestamps || watch.compiler.fileTimestamps;
|
||||||
|
|
||||||
WatchTimestampsPlugin.prototype.apply = function (compiler) {
|
Object.keys(timestamps).forEach(filepath => {
|
||||||
compiler.plugin('watch-run', (watch, callback) => {
|
if (patterns.some(pat => pat instanceof RegExp ? pat.test(filepath) : filepath.indexOf(pat) === 0)) {
|
||||||
let patterns = this.patterns;
|
let time = fs.statSync(filepath).mtime;
|
||||||
let timestamps = watch.fileTimestamps || watch.compiler.fileTimestamps;
|
if (timestamps instanceof Map) timestamps.set(filepath, time);
|
||||||
|
else timestamps[filepath] = time;
|
||||||
Object.keys(timestamps).forEach( filepath => {
|
}
|
||||||
if (patterns.some( pat => pat instanceof RegExp ? pat.test(filepath) : filepath.indexOf(pat)===0 )) {
|
});
|
||||||
let time = fs.statSync(filepath).mtime;
|
callback();
|
||||||
if (timestamps instanceof Map) timestamps.set(filepath, time);
|
|
||||||
else timestamps[filepath] = time;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
callback();
|
}
|
||||||
});
|
|
||||||
};
|
};
|
||||||
Reference in New Issue
Block a user