diff --git a/client-src/index.js b/client-src/index.js index b6ff70a4e7..5e1d367732 100644 --- a/client-src/index.js +++ b/client-src/index.js @@ -137,8 +137,22 @@ const onSocketMessage = { reloadApp(options, status); }, - 'content-changed': function contentChanged() { - log.info('Content base changed. Reloading...'); + // TODO: remove in v5 in favor of 'static-changed' + 'content-changed': function contentChanged(file) { + log.info( + `${ + file ? `"${file}"` : 'Content' + } from static directory was changed. Reloading...` + ); + + self.location.reload(); + }, + 'static-changed': function staticChanged(file) { + log.info( + `${ + file ? `"${file}"` : 'Content' + } from static directory was changed. Reloading...` + ); self.location.reload(); }, diff --git a/lib/Server.js b/lib/Server.js index 5261f7f7e8..bb0851a59a 100644 --- a/lib/Server.js +++ b/lib/Server.js @@ -1121,7 +1121,7 @@ class Server { // disabling refreshing on changing the content if (this.options.liveReload) { watcher.on('change', () => { - this.sockWrite(this.sockets, 'content-changed'); + this.sockWrite(this.sockets, 'static-changed', watchPath); }); } diff --git a/test/client/__snapshots__/index.test.js.snap.webpack4 b/test/client/__snapshots__/index.test.js.snap.webpack4 index 9cea051989..8c2e9e9f25 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack4 +++ b/test/client/__snapshots__/index.test.js.snap.webpack4 @@ -80,7 +80,13 @@ Array [ ] `; -exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`; +exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`; exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; @@ -103,6 +109,7 @@ Array [ "overlay": [Function], "progress": [Function], "progress-update": [Function], + "static-changed": [Function], "still-ok": [Function], "warnings": [Function], }, diff --git a/test/client/__snapshots__/index.test.js.snap.webpack5 b/test/client/__snapshots__/index.test.js.snap.webpack5 index 9cea051989..8c2e9e9f25 100644 --- a/test/client/__snapshots__/index.test.js.snap.webpack5 +++ b/test/client/__snapshots__/index.test.js.snap.webpack5 @@ -80,7 +80,13 @@ Array [ ] `; -exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content base changed. Reloading..."`; +exports[`index should run onSocketMessage['content-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['content-changed'](file) 1`] = `"\\"/public/assets/index.html\\" from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['static-changed'] 1`] = `"Content from static directory was changed. Reloading..."`; + +exports[`index should run onSocketMessage['static-changed'](file) 1`] = `"\\"/static/assets/index.html\\" from static directory was changed. Reloading..."`; exports[`index should run onSocketMessage['still-ok'] 1`] = `"Nothing changed."`; @@ -103,6 +109,7 @@ Array [ "overlay": [Function], "progress": [Function], "progress-update": [Function], + "static-changed": [Function], "still-ok": [Function], "warnings": [Function], }, diff --git a/test/client/index.test.js b/test/client/index.test.js index 452d2b4ddd..1f8db5cdc4 100644 --- a/test/client/index.test.js +++ b/test/client/index.test.js @@ -185,6 +185,27 @@ describe('index', () => { expect(self.location.reload).toBeCalled(); }); + test("should run onSocketMessage['content-changed'](file)", () => { + onSocketMessage['content-changed']('/public/assets/index.html'); + + expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); + expect(self.location.reload).toBeCalled(); + }); + + test("should run onSocketMessage['static-changed']", () => { + onSocketMessage['static-changed'](); + + expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); + expect(self.location.reload).toBeCalled(); + }); + + test("should run onSocketMessage['static-changed'](file)", () => { + onSocketMessage['static-changed']('/static/assets/index.html'); + + expect(log.log.info.mock.calls[0][0]).toMatchSnapshot(); + expect(self.location.reload).toBeCalled(); + }); + test('should run onSocketMessage.warnings', () => { { const res = onSocketMessage.warnings([