UNPKG

1.49 kBJavaScriptView Raw
1'use strict';
2if (typeof window === 'object') {
3 var hotClient = require('webpack-hot-middleware/client?noInfo=false&reload=true&quiet=false&autoConnect=false');
4 var currentHash;
5 hotClient.setOptionsAndConnect({
6 path: EASY_ENV_HOST_URL + '/__webpack_hmr'
7 });
8 hotClient.subscribeAll(function(event) {
9 if (event.action === 'built' && currentHash) {
10 var request = new XMLHttpRequest();
11 var requestPath = EASY_ENV_PUBLIC_PATH + currentHash + '.hot-update.json';
12 request.open("GET", requestPath, true);
13 request.timeout = 5000;
14 request.send(null);
15 request.onreadystatechange = function() {
16 if (request.readyState === 4) {
17 if (request.status === 200) {
18 try {
19 var update = JSON.parse(request.responseText);
20 var c = update.c;
21 if (!c || JSON.stringify(c) === '{}' || /:true/.test(JSON.stringify(c))) {
22 var links = document.getElementsByTagName('link');
23 for (var i = 0; i < links.length; i++) {
24 var href = links[i].href;
25 if (href && /\.css$/.test(href)) {
26 links[i].href = href;
27 console.log('[HMR] ' + href + ' updated.');
28 }
29 }
30 }
31 } catch (e) {
32 console.log('Get hot-update.json content error', e);
33 }
34 }
35 }
36 };
37 }
38 currentHash = event.hash || currentHash;
39 });
40}
\No newline at end of file