Skip to content

Commit

Permalink
fix(client): add default fallback for client (#2015)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
knagaitsev authored and hiroppy committed Jun 17, 2019
1 parent 84955f8 commit d26b444
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
14 changes: 13 additions & 1 deletion client-src/default/socket.js
Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions client-src/default/webpack.config.js
@@ -1,5 +1,7 @@
'use strict';

const webpack = require('webpack');

module.exports = {
mode: 'production',
module: {
Expand All @@ -15,4 +17,12 @@ module.exports = {
},
],
},
plugins: [
new webpack.NormalModuleReplacementPlugin(/\/clients\//, (resource) => {
resource.request = resource.request.replace(
/\/clients\//,
'/../clients/'
);
}),
],
};
7 changes: 7 additions & 0 deletions 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 = {
Expand Down Expand Up @@ -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/'
);
}),
],
};
2 changes: 1 addition & 1 deletion test/e2e/ClientOptions.test.js
Expand Up @@ -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) => {
Expand Down

0 comments on commit d26b444

Please sign in to comment.