webpack-watch-files-plugin icon indicating copy to clipboard operation
webpack-watch-files-plugin copied to clipboard

Plugin not rebuildng changes from watched files

Open titantwentyone opened this issue 5 years ago • 5 comments

I am having a similar issue as described in #8

Ubuntu 18.04 LTS Webpack 4.41.6

My config is:

...
new WatchExternalFilesPlugin({
    files: [
      './src/data/data.json',
      './src/html/partials/*.part'
    ],
    verbose: true
})
...

When dev server is running, the plugin correctly states:

Additional files watched :  [
  "/var/www/local//dev/src/data/data.json",
  "/var/www/local//dev/src/html/partials/footer.part",
  "/var/www/local//dev/src/html/partials/head.part",
  "/var/www/local//dev/src/html/partials/header.part",
  "/var/www/local//dev/src/html/partials/socialmedia.part"
]

If changes are made to a .part" file the compilation runs, triggers a browser reload and completes with 「wdm」: Compiled successfully.but the changes are not reflected.

When I edit a "part" file, the changes are not reflected immediately but when I edit another file, say a 'htm' or 'scss', the changes do come through.

This also happens when using webpack --watch.

titantwentyone avatar Feb 21 '20 15:02 titantwentyone

Same problem here. Did you resolve it ?

Kakulukian avatar Mar 16 '20 14:03 Kakulukian

@titantwentyone maybe the browser is serving an old version from the cache. Have tried going to Devtools > Network tab and checking 'disable cache'? Changes to .html files might be coming through because the browser doesn't cache HTML as aggressively...

codemaster138 avatar Aug 30 '20 11:08 codemaster138

Hi ! I've updated this plugin this morning. Your bug seems to come from the cache. If you check the compiled file, do you see the modification ?

Fridus avatar Aug 31 '20 08:08 Fridus

I'm having the same issue. I am trying to run a script each time a file is modified at the beggining of the webpack compilation, which creates a new file. When I edit a file that I'm watching with this plugin and hit save, webpack --watch recompiles and runs the script, which then creates this file, but it's content is relevant to prior version of file, not the newest version.

jpnieto avatar Nov 12 '20 13:11 jpnieto

This plugin successfully triggers a compiler "emit" event whenever the external files change.

However, because those files are not included in the actual webpack bundle, no build info or output from webpack is generated, the actual asset which webpack outputs never changes. Other plugins which may be monitoring the output of webpack (like the nodemon-webpack-plugin), will never re-run.

I came up with this hack to force a rebuild by "touch"ing the output asset every time the "compile" event is emitted:

const path = require('path');
const touch = require('touch');

class WebpackForceRebuildOnEmitPlugin {
  apply(compiler) {
    compiler.hooks.emit.tapAsync('WebpackForceRebuildOnEmitPlugin', (compilation, callback) => {
      const outputPath = compilation.outputOptions.path;
      const firstAssetName = compilation.getAssets()[0].name;
      const assetToTouch = path.resolve(outputPath, firstAssetName);
      touch(assetToTouch);
      callback();
    });
  }
}

sarink avatar Jan 04 '21 02:01 sarink