From d26b444fe118f7abd53e1ba708421470fd147a72 Mon Sep 17 00:00:00 2001 From: Loonride Date: Mon, 17 Jun 2019 18:05:54 -0500 Subject: [PATCH] fix(client): add default fallback for client (#2015) * fix(client): add default fallback for client * test(server): update entry snapshot * fix(client): move SockJSClient definition * fix(client): update SockJSClient path resolution * fix(client): add correct entry path --- client-src/default/socket.js | 14 +++++++++++++- client-src/default/webpack.config.js | 10 ++++++++++ client-src/live/webpack.config.js | 7 +++++++ test/e2e/ClientOptions.test.js | 2 +- 4 files changed, 31 insertions(+), 2 deletions(-) diff --git a/client-src/default/socket.js b/client-src/default/socket.js index 4c8bcbba20..7752ffea8a 100644 --- a/client-src/default/socket.js +++ b/client-src/default/socket.js @@ -4,7 +4,19 @@ /* eslint-disable camelcase */ -const Client = __webpack_dev_server_client__; + +// this SockJSClient is here as a default fallback, in case inline mode +// is off or the client is not injected. This will be switched to +// WebsocketClient when it becomes the default + +// important: the path to SockJSClient here is made to work in the 'client' +// directory, but is updated via the webpack compilation when compiled from +// the 'client-src' directory +const Client = + typeof __webpack_dev_server_client__ !== 'undefined' + ? __webpack_dev_server_client__ + : // eslint-disable-next-line import/no-unresolved + require('./clients/SockJSClient'); let retries = 0; let client = null; diff --git a/client-src/default/webpack.config.js b/client-src/default/webpack.config.js index a0b70901ca..ac001f26d7 100644 --- a/client-src/default/webpack.config.js +++ b/client-src/default/webpack.config.js @@ -1,5 +1,7 @@ 'use strict'; +const webpack = require('webpack'); + module.exports = { mode: 'production', module: { @@ -15,4 +17,12 @@ module.exports = { }, ], }, + plugins: [ + new webpack.NormalModuleReplacementPlugin(/\/clients\//, (resource) => { + resource.request = resource.request.replace( + /\/clients\//, + '/../clients/' + ); + }), + ], }; diff --git a/client-src/live/webpack.config.js b/client-src/live/webpack.config.js index 75e693210a..3887b38b2b 100644 --- a/client-src/live/webpack.config.js +++ b/client-src/live/webpack.config.js @@ -1,6 +1,7 @@ 'use strict'; const path = require('path'); +const webpack = require('webpack'); const CopyPlugin = require('copy-webpack-plugin'); module.exports = { @@ -33,5 +34,11 @@ module.exports = { to: path.resolve(__dirname, '../../client/live.html'), }, ]), + new webpack.NormalModuleReplacementPlugin(/\/clients\//, (resource) => { + resource.request = resource.request.replace( + /\/clients\//, + '/../clients/' + ); + }), ], }; diff --git a/test/e2e/ClientOptions.test.js b/test/e2e/ClientOptions.test.js index 3fb4160245..07d3bba8d9 100644 --- a/test/e2e/ClientOptions.test.js +++ b/test/e2e/ClientOptions.test.js @@ -166,7 +166,7 @@ describe('Client complex inline script path with sockPort', () => { }); // previously, using sockPort without sockPath had the ability -// to alter the sockPath (based on a bug in client-src/index.js) +// to alter the sockPath (based on a bug in client-src/default/index.js) // so we need to make sure sockPath is not altered in this case describe('Client complex inline script path with sockPort, no sockPath', () => { beforeAll((done) => {