From ccf71556a626cd6ca9f44f32bc8f2f8f3d0caaeb Mon Sep 17 00:00:00 2001 From: Jason Miller Date: Tue, 27 Mar 2018 20:39:13 -0400 Subject: [PATCH] Use classes for webpack plugins. --- config/watch-timestamps-plugin.js | 38 +++++++++++++++---------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/config/watch-timestamps-plugin.js b/config/watch-timestamps-plugin.js index d85ea462..d0a8eadf 100644 --- a/config/watch-timestamps-plugin.js +++ b/config/watch-timestamps-plugin.js @@ -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) { - this.patterns = patterns; -} + apply(compiler) { + compiler.plugin('watch-run', (watch, callback) => { + let patterns = this.patterns; + let timestamps = watch.fileTimestamps || watch.compiler.fileTimestamps; -WatchTimestampsPlugin.prototype.apply = function (compiler) { - compiler.plugin('watch-run', (watch, callback) => { - let patterns = this.patterns; - let timestamps = watch.fileTimestamps || watch.compiler.fileTimestamps; - - 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; - 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; + if (timestamps instanceof Map) timestamps.set(filepath, time); + else timestamps[filepath] = time; + } + }); + callback(); }); - callback(); - }); -}; \ No newline at end of file + } +};