statianzo / webpack-livereload-plugin

LiveReload during webpack --watch
ISC License
204 stars 51 forks source link

Enable reload on custom logic #66

Open andreyvolokitin opened 3 years ago

andreyvolokitin commented 3 years ago

Usually page gets reloaded when compilation hash changes, but sometimes it may be desirable to reload even if hash stays the same. I.e. CopyWebpackPlugin can emit changed files, but it doesn't change compilation hash, so the page doesn't reload. In this case you could check emitted files in options callback, to decide if reloading is required:

shouldReload(compilation) {
    return Array.from(compilation.emittedAssets).some(assetName => path.extname(assetName) === '.php');
}
web-mi commented 3 years ago

Maybe we could change the logic more globally/configureable. 1) New option useChildHash (default: true) to disable check for compilation.children hashes. 2) New option useCompilationHash (default: true) to disable check for compilation hash.

I currently have no time to try it but i think the above two logics are obsolet because we got the function _fileIgnoredOrNotEmitted which is already checking if a file is emitted but to ensure all installations are still working we should add it as optional option first.

For your example maybe its just enough to disable the compilationHash option because your files will exists in compilation.children.

@statianzo or am i wrong or forgot something?