forked from webpack-contrib/webpack-serve
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwatch-content.config.js
47 lines (41 loc) · 939 Bytes
/
watch-content.config.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
const path = require('path');
const chokidar = require('chokidar');
const stringify = require('json-stringify-safe');
const WebSocket = require('ws');
module.exports = {
entry: {
index: [path.resolve(__dirname, 'app.js')],
},
mode: 'development',
output: {
filename: 'output.js',
},
};
module.exports.serve = {
content: [__dirname],
hot: {
host: 'localhost',
port: 8090,
},
on: {
listening(server) {
const socket = new WebSocket('ws://localhost:8090');
const watchPath = __dirname;
const options = {};
const watcher = chokidar.watch(watchPath, options);
watcher.on('change', () => {
const data = {
type: 'broadcast',
data: {
type: 'window-reload',
data: {},
},
};
socket.send(stringify(data));
});
server.on('close', () => {
watcher.close();
});
},
},
};