qmzreact 1.0.18 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/conf/dev-server.js +24 -2
- package/package.json +1 -1
package/conf/dev-server.js
CHANGED
|
@@ -22,9 +22,15 @@ var devMiddleware = require('webpack-dev-middleware')(compiler, {
|
|
|
22
22
|
}
|
|
23
23
|
})
|
|
24
24
|
var hotMiddleware = require('webpack-hot-middleware')(compiler)
|
|
25
|
+
// capture previous NODE_STATUS so we can detect a restart that happened
|
|
26
|
+
// before the compilation changed it to "running"
|
|
27
|
+
var previousNodeStatus = process.env.NODE_STATUS || ''
|
|
25
28
|
// // force page reload when html-webpack-plugin template changes
|
|
26
29
|
compiler.hooks.make.tap('compilation', function (compilation) {
|
|
27
30
|
compilation.hooks.finishModules.tap('html-webpack-plugin-after-emit', function (modules) {
|
|
31
|
+
// capture the status before flipping to running so done hook can
|
|
32
|
+
// know if we came from a 'rebuild' state
|
|
33
|
+
previousNodeStatus = process.env.NODE_STATUS
|
|
28
34
|
process.env.NODE_STATUS = "running";
|
|
29
35
|
hotMiddleware.publish({ action: 'reload' })
|
|
30
36
|
})
|
|
@@ -32,8 +38,24 @@ compiler.hooks.make.tap('compilation', function (compilation) {
|
|
|
32
38
|
// print compiler finished info
|
|
33
39
|
compiler.hooks.done.tap('AfterCompiler', function(stats) {
|
|
34
40
|
setTimeout(() => {
|
|
35
|
-
|
|
36
|
-
|
|
41
|
+
// If we were restarted (previousNodeStatus === 'rebuild') then the
|
|
42
|
+
// hot middleware client in the browser may not have reconnected yet to
|
|
43
|
+
// receive a single publish. Send the reload multiple times with a few
|
|
44
|
+
// retries to increase the chance the client receives it.
|
|
45
|
+
if (previousNodeStatus === 'rebuild' || process.env.NODE_STATUS === 'rebuild') {
|
|
46
|
+
var delays = [0, 500, 1500, 3000]
|
|
47
|
+
delays.forEach(function (d) {
|
|
48
|
+
setTimeout(function () {
|
|
49
|
+
try {
|
|
50
|
+
hotMiddleware.publish({ action: 'reload' })
|
|
51
|
+
} catch (e) {
|
|
52
|
+
// swallow any errors from publish and continue retries
|
|
53
|
+
console.error('hotMiddleware.publish error:', e && e.message)
|
|
54
|
+
}
|
|
55
|
+
}, d)
|
|
56
|
+
})
|
|
57
|
+
// reset captured status so subsequent compilations behave normally
|
|
58
|
+
previousNodeStatus = ''
|
|
37
59
|
}
|
|
38
60
|
console.log('webpack \x1b[1mcompiled \x1B[32mfinished \x1B[37min',new Date().toLocaleString(),'\x1b[0m')
|
|
39
61
|
}, 2000)
|