Skip to content

Commit 1e3e656

Browse files
fix: client compatibility with IE11/IE10/IE9 (#3129)
1 parent 3d91e69 commit 1e3e656

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+6848
-7455
lines changed

.eslintrc.js

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
module.exports = {
44
extends: ['webpack', 'prettier'],
5-
globals: {
6-
document: true,
7-
window: true,
8-
},
95
parserOptions: {
106
sourceType: 'script',
11-
ecmaVersion: 10,
7+
ecmaVersion: 2018,
8+
},
9+
env: {
10+
node: true,
11+
es6: true,
1212
},
1313
rules: {
1414
curly: 'error',
@@ -21,12 +21,30 @@ module.exports = {
2121
'global-require': 'off',
2222
},
2323
overrides: [
24+
{
25+
files: ['client-src/**/*.js'],
26+
env: {
27+
browser: true,
28+
},
29+
},
2430
{
2531
files: ['test/**/*.js'],
2632
rules: {
2733
'no-console': 'off',
2834
},
2935
},
36+
{
37+
files: [
38+
'test/client/**/*.js',
39+
'test/e2e/**/*.js',
40+
'test/fixtures/**/*.js',
41+
'test/server/liveReload-option.test.js',
42+
],
43+
env: {
44+
browser: true,
45+
node: true,
46+
},
47+
},
3048
{
3149
files: ['examples/**/*.js'],
3250
env: {

babel.config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,16 @@ module.exports = (api) => {
44
api.cache(true);
55

66
return {
7-
presets: ['@babel/preset-env'],
7+
presets: [
8+
[
9+
'@babel/preset-env',
10+
{
11+
targets: {
12+
node: '0.12',
13+
},
14+
},
15+
],
16+
],
817
env: {
918
test: {
1019
plugins: ['@babel/plugin-transform-runtime'],

client-src/clients/SockJSClient.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
'use strict';
22

3-
const SockJS = require('sockjs-client/dist/sockjs');
4-
const { log } = require('../default/utils/log');
3+
const SockJS = require('../modules/sockjs-client');
4+
const { log } = require('../utils/log');
55
const BaseClient = require('./BaseClient');
66

77
module.exports = class SockJSClient extends BaseClient {
88
constructor(url) {
99
super();
10+
1011
const sockUrl = url.replace(/^(?:chrome-extension|file)/i, 'http');
11-
this.sock = new SockJS(sockUrl);
1212

13+
this.sock = new SockJS(sockUrl);
1314
this.sock.onerror = (err) => {
1415
log.error(err);
1516
};

client-src/clients/WebsocketClient.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
'use strict';
22

3-
/* global WebSocket */
4-
5-
const { log } = require('../default/utils/log');
3+
const { log } = require('../utils/log');
64
const BaseClient = require('./BaseClient');
75

86
module.exports = class WebsocketClient extends BaseClient {
97
constructor(url) {
108
super();
9+
1110
const wsUrl = url.replace(/^(?:http|chrome-extension|file)/i, 'ws');
12-
this.client = new WebSocket(wsUrl);
1311

12+
this.client = new WebSocket(wsUrl);
1413
this.client.onerror = (err) => {
1514
log.error(err);
1615
};

client-src/default/webpack.config.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

client-src/default/index.js renamed to client-src/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

3-
/* global __resourceQuery WorkerGlobalScope self */
4-
const stripAnsi = require('../transpiled-modules/strip-ansi');
3+
/* global __resourceQuery WorkerGlobalScope */
4+
5+
const stripAnsi = require('./modules/strip-ansi');
56
const socket = require('./socket');
67
const overlay = require('./overlay');
78
const { log, setLogLevel } = require('./utils/log');

client-src/modules/logger/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
3+
// eslint-disable-next-line import/no-extraneous-dependencies
4+
require('core-js/stable/symbol');
5+
6+
module.exports = require('webpack/lib/logging/runtime');
File renamed without changes.

client-src/default/socket.js renamed to client-src/socket.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Client =
1111
typeof __webpack_dev_server_client__ !== 'undefined'
1212
? __webpack_dev_server_client__
1313
: // eslint-disable-next-line import/no-unresolved
14-
require('../clients/WebsocketClient');
14+
require('./clients/WebsocketClient');
1515

1616
let retries = 0;
1717
let client = null;
@@ -37,6 +37,7 @@ const socket = function initSocket(url, handlers) {
3737
// Respectfully copied from the package `got`.
3838
// eslint-disable-next-line no-mixed-operators, no-restricted-properties
3939
const retryInMs = 1000 * Math.pow(2, retries) + Math.random() * 100;
40+
4041
retries += 1;
4142

4243
setTimeout(() => {

client-src/sockjs/webpack.config.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

client-src/transpiled-modules/log.js

Lines changed: 0 additions & 3 deletions
This file was deleted.

client-src/transpiled-modules/webpack.config.js

Lines changed: 0 additions & 47 deletions
This file was deleted.

client-src/default/utils/createSocketUrl.js renamed to client-src/utils/createSocketUrl.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
/* global self */
4-
53
const url = require('url');
64
const getCurrentScriptSource = require('./getCurrentScriptSource');
75

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,16 @@
11
'use strict';
22

3-
const log = require('../../transpiled-modules/log');
3+
const logger = require('../modules/logger');
44

55
const name = 'webpack-dev-server';
66
// default level is set on the client side, so it does not need
77
// to be set by the CLI or API
88
const defaultLevel = 'info';
99

1010
function setLogLevel(level) {
11-
log.configureDefaultLogger({
12-
level,
13-
});
11+
logger.configureDefaultLogger({ level });
1412
}
1513

1614
setLogLevel(defaultLevel);
1715

18-
module.exports = {
19-
log: log.getLogger(name),
20-
setLogLevel,
21-
};
16+
module.exports = { log: logger.getLogger(name), setLogLevel };

client-src/default/utils/reloadApp.js renamed to client-src/utils/reloadApp.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
/* global WorkerGlobalScope self */
4-
53
const { log } = require('./log');
64

75
function reloadApp(
@@ -11,10 +9,14 @@ function reloadApp(
119
if (isUnloading || !hotReload) {
1210
return;
1311
}
12+
1413
if (hot) {
1514
log.info('App hot update...');
15+
1616
const hotEmitter = require('webpack/hot/emitter');
17+
1718
hotEmitter.emit('webpackHotUpdate', currentHash);
19+
1820
if (typeof self !== 'undefined' && self.window) {
1921
// broadcast update to window
2022
self.postMessage(`webpackHotUpdate${currentHash}`, '*');
@@ -23,13 +25,15 @@ function reloadApp(
2325
// allow refreshing the page only if liveReload isn't disabled
2426
else if (liveReload) {
2527
let rootWindow = self;
28+
2629
// use parent window for reload (in case we're in an iframe with no valid src)
2730
const intervalId = self.setInterval(() => {
2831
if (rootWindow.location.protocol !== 'about:') {
2932
// reload immediately if protocol is valid
3033
applyReload(rootWindow, intervalId);
3134
} else {
3235
rootWindow = rootWindow.parent;
36+
3337
if (rootWindow.parent === rootWindow) {
3438
// if parent equals current window we've reached the root which would continue forever, so trigger a reload anyways
3539
applyReload(rootWindow, intervalId);

client-src/default/utils/sendMessage.js renamed to client-src/utils/sendMessage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
/* global __resourceQuery WorkerGlobalScope self */
3+
/* global __resourceQuery WorkerGlobalScope */
44

55
// Send messages to the outside, so plugins can consume it.
66
function sendMsg(type, data) {

client-src/webpack.config.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use strict';
2+
3+
const path = require('path');
4+
const webpack = require('webpack');
5+
const { merge } = require('webpack-merge');
6+
7+
const baseForModules = {
8+
devtool: false,
9+
mode: 'development',
10+
output: {
11+
path: path.resolve(__dirname, '../client/modules'),
12+
libraryTarget: 'commonjs2',
13+
},
14+
target: webpack.webpack ? ['web', 'es5'] : 'web',
15+
module: {
16+
rules: [
17+
{
18+
test: /\.js$/,
19+
use: [
20+
{
21+
loader: 'babel-loader',
22+
},
23+
],
24+
},
25+
],
26+
},
27+
};
28+
29+
module.exports = [
30+
merge(baseForModules, {
31+
entry: path.join(__dirname, 'modules/logger/index.js'),
32+
output: {
33+
filename: 'logger/index.js',
34+
},
35+
module: {
36+
rules: [
37+
{
38+
test: /\.js$/,
39+
use: [
40+
{
41+
loader: 'babel-loader',
42+
options: {
43+
plugins: ['@babel/plugin-transform-object-assign'],
44+
},
45+
},
46+
],
47+
},
48+
],
49+
},
50+
plugins: [
51+
new webpack.NormalModuleReplacementPlugin(
52+
/^tapable\/lib\/SyncBailHook/,
53+
path.join(__dirname, 'modules/logger/SyncBailHookFake.js')
54+
),
55+
],
56+
}),
57+
merge(baseForModules, {
58+
entry: path.join(__dirname, 'modules/strip-ansi/index.js'),
59+
output: {
60+
filename: 'strip-ansi/index.js',
61+
},
62+
}),
63+
merge(baseForModules, {
64+
entry: path.join(__dirname, 'modules/sockjs-client/index.js'),
65+
output: {
66+
filename: 'sockjs-client/index.js',
67+
library: 'SockJS',
68+
libraryTarget: 'umd',
69+
globalObject: "(typeof self !== 'undefined' ? self : this)",
70+
},
71+
}),
72+
];

0 commit comments

Comments
 (0)