-
Notifications
You must be signed in to change notification settings - Fork 52
/
entry.js
63 lines (56 loc) · 1.44 KB
/
entry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* eslint-disable */
import url from 'url';
import SockJS from 'sockjs-client';
import {
setEditorHandler,
reportBuildError,
startReportingRuntimeErrors,
} from 'react-error-overlay'
import launchEditorEndpoint from 'react-dev-utils/launchEditorEndpoint'
import formatWebpackMessages from 'react-dev-utils/formatWebpackMessages';
const connection = new SockJS(
url.format({
protocol: window.location.protocol,
hostname: window.location.hostname,
port: window.location.port,
// Hardcoded in WebpackDevServer
pathname: '/sockjs-node',
})
);
setEditorHandler(errorLocation => {
// Keep this sync with errorOverlayMiddleware.js
fetch(
launchEditorEndpoint +
'?fileName=' +
window.encodeURIComponent(errorLocation.fileName) +
'&lineNumber=' +
window.encodeURIComponent(errorLocation.lineNumber || 1) +
'&colNumber=' +
window.encodeURIComponent(errorLocation.colNumber || 1),
)
})
startReportingRuntimeErrors({
onError() {
if (module.hot) {
module.hot.addStatusHandler(status => {
if (status === 'apply') {
window.location.reload()
}
})
}
},
})
connection.onmessage = function(e) {
const {type, data} = JSON.parse(e.data);
switch (type) {
case 'errors':
const {errors} = formatWebpackMessages({
errors: data,
warnings: [],
});
reportBuildError(errors[0]);
break;
default:
// Do nothing.
}
};