-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
28 lines (25 loc) · 893 Bytes
/
index.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
var io = require('socket.io')(8196)
const socket = {
init (data) {
data.html += '<script src="http://localhost:8196/socket.io/socket.io.js"></script>'
data.html += '<script>var socket = io.connect("http://localhost:8196");socket.on("reload", function(){window.location.reload()});</script>'
},
reload () {
io.emit('reload')
}
}
class HtmlWebpackReloadPlugin {
apply (compiler) {
compiler.hooks.compilation.tap('HtmlWebpackReload', function (compilation) {
compilation.hooks.htmlWebpackPluginBeforeHtmlProcessing.tapAsync('HtmlWebpackReload', function (data, callback) {
socket.init(data)
callback(null, data)
})
compilation.hooks.htmlWebpackPluginAfterEmit.tapAsync('HtmlWebpackReload', function (data, callback) {
socket.reload()
callback(null, data)
})
})
}
}
module.exports = HtmlWebpackReloadPlugin