Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ Add a script tag to your page pointed at the livereload server
ignore nothing. It is also possible to define an array and use multiple [anymatch](https://github.com/micromatch/anymatch) patterns.
- `delay` - (Default: `0`) amount of milliseconds by which to delay the live reload (in case build takes longer)
- `useSourceHash` - (Default: `false`) create hash for each file source and only notify livereload if hash has changed
- `shouldReload` - (Default: `function`) callback which gets called with a `compilation` argument to decide if page should reload, by returning a boolean. 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. In this case you could check emitted files to decide if reloading is required:

```
shouldReload(compilation) {
return Array.from(compilation.emittedAssets).some(assetName => path.extname(assetName) === '.php');
}
```

## Why?

Expand Down
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class LiveReloadPlugin {
useSourceHash: false,
appendScriptTag: false,
delay: 0,
shouldReload(compilation) {
return false;
},
}, options);

// Random alphanumeric string appended to id to allow multiple instances of live reload
Expand Down Expand Up @@ -152,7 +155,7 @@ class LiveReloadPlugin {
if (
this._isRunning()
&& include.length > 0

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this code and in my case include.length is already 0 since none of the "assets" in the compilation has changed. In my scenario the shouldReload-call should need to "winn" over the include as well.

&& (hash !== this.lastHash || !LiveReloadPlugin.arraysEqual(childHashes, this.lastChildHashes))
&& ((hash !== this.lastHash || !LiveReloadPlugin.arraysEqual(childHashes, this.lastChildHashes)) || this.options.shouldReload(compilation))
) {
this.lastHash = hash;
this.lastChildHashes = childHashes;
Expand Down