Fridus / webpack-watch-files-plugin

Webpack watch additional files
41 stars 8 forks source link

Plugin not rebuildng changes from watched files #12

Open titantwentyone opened 4 years ago

titantwentyone commented 4 years ago

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.

Kakulukian commented 4 years ago

Same problem here. Did you resolve it ?

codemaster138 commented 4 years ago

@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...

Fridus commented 4 years ago

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 ?

jpnieto commented 3 years ago

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.

sarink commented 3 years ago

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();
    });
  }
}