Can webpack report which file triggered a compilation in watch mode?

后端 未结 4 673
清酒与你
清酒与你 2021-01-04 07:46

I would like for Webpack to log which file triggered my watch mode build.

I have configured a plugin that listens to the watch-run compiler event hook l

4条回答
  •  囚心锁ツ
    2021-01-04 08:20

    The plugin I used for this in Webpack 4:

    class WatchRunPlugin {
      apply(compiler) {
        compiler.hooks.watchRun.tap('WatchRun', (comp) => {
          const changedTimes = comp.watchFileSystem.watcher.mtimes;
          const changedFiles = Object.keys(changedTimes)
            .map(file => `\n  ${file}`)
            .join('');
          if (changedFiles.length) {
            console.log("====================================")
            console.log('NEW BUILD FILES CHANGED:', changedFiles);
            console.log("====================================")
          }
        });
      }
    }
    

提交回复
热议问题