Can webpack tell which file caused compilation in view mode?

I would like Webpack to log which file caused the view-mode assembly.

I configured a plugin that listens for the compiler event tag watch-runas follows:

function() {
  this.plugin("watch-run", function(watching, callback) {
    // maybe something in `watching` will indicate the changed file?
    // when I find out what it is, `console.log` it here
    callback();
  });
}

// Example output: "/Users/aaron/git/test/index.js" was changed, new build triggered

But I can’t understand where the changed file information can be, if any.

The Webpack documentation in this area is really missing. There are no examples on the Compiler Event Hook page (only a message explaining that examples will appear soon), and old v1 documentation does not much better develop the properties / methods available in the watching/ object compiler.

Any help or guidance is appreciated.

+6
1

webpack, , . , , , . , :

watching.compiler.watchFileSystem.watcher.mtimes

, , , , . , , , .

, ( ):

this.plugin("watch-run", (watching, done) => {
  const changedTimes = watching.compiler.watchFileSystem.watcher.mtimes;
  const changedFiles = Object.keys(changedTimes)
    .map(file => `\n  ${file}`)
    .join("");
  if (changedFiles.length) {
    console.log("New build triggered, files changed:", changedFiles);
  }
  done();
});

:

New build triggered, files changed:
  /path/to/app/src/components/item/Item.js
  /path/to/app/src/App.js

. , .

+10

Source: https://habr.com/ru/post/1016200/


All Articles