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

后端 未结 4 676
清酒与你
清酒与你 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:19

    In webpack 4 you can access to watcher in that way:

    getChangedFiles(compiler) {
      const { watchFileSystem } = compiler;
      const watcher = watchFileSystem.watcher || watchFileSystem.wfs.watcher;
    
      return Object.keys(watcher.mtimes);
    }
    

    latter in watchRun hook

    compiler.hooks.watchRun.tapAsync('plugin name', (_compiler, done) => {
      const changedFile = this.getChangedFiles(_compiler)
    
      // ...
    
      return done();
    });
    

提交回复
热议问题