Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(client): add default fallback for client #2015

Merged
merged 6 commits into from Jun 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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) => {
alexander-akait marked this conversation as resolved.
Show resolved Hide resolved
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) => {
Copy link
Member

Choose a reason for hiding this comment

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

memo: We will delete this plugin at the next major version because we can change the directory structure.

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