@@ -314,11 +314,11 @@ This is useful for plugins that need to react only to specific file changes
314314``` js
315315class WatchNotifierPlugin {
316316 apply (compiler ) {
317- compiler .hooks .watchRun .tap (' WatchNotifierPlugin' , (compiler ) => {
317+ compiler .hooks .watchRun .tap (" WatchNotifierPlugin" , (compiler ) => {
318318 if (compiler .modifiedFiles ) {
319- const changedFiles = Array . from ( compiler .modifiedFiles )
319+ const changedFiles = [ ... compiler .modifiedFiles ]
320320 .map ((file ) => ` • ${ file} ` )
321- .join (' \n ' );
321+ .join (" \n " );
322322
323323 console .log (` \n Files changed:\n ${ changedFiles} ` );
324324 }
@@ -328,7 +328,9 @@ class WatchNotifierPlugin {
328328
329329module .exports = WatchNotifierPlugin;
330330```
331+
331332> ** Note** :
333+ >
332334> - ` compiler.modifiedFiles ` is a ` Set ` , not an array
333335> - It is ` undefined ` on the first (cold) build
334336> - It is only populated during watch rebuilds
@@ -341,12 +343,12 @@ that webpack does not track by default, you must tell webpack to watch them.
341343The ` compilation.fileDependencies ` set allows you to add such files.
342344
343345``` js
344- const path = require (' path' );
346+ const path = require (" node: path" );
345347
346348class TemplateWatchPlugin {
347349 apply (compiler ) {
348- compiler .hooks .compilation .tap (' TemplateWatchPlugin' , (compilation ) => {
349- const templatePath = path .resolve (__dirname , ' my-template.html' );
350+ compiler .hooks .compilation .tap (" TemplateWatchPlugin" , (compilation ) => {
351+ const templatePath = path .resolve (__dirname , " my-template.html" );
350352
351353 // Ensure webpack watches this file
352354 compilation .fileDependencies .add (templatePath);
@@ -356,6 +358,7 @@ class TemplateWatchPlugin {
356358
357359module .exports = TemplateWatchPlugin;
358360```
361+
359362Without calling ` fileDependencies.add() ` , webpack will not trigger
360363a rebuild when the file changes — even if your plugin depends on it.
361364
0 commit comments