This repository was archived by the owner on Jan 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev.js
More file actions
54 lines (44 loc) · 1.22 KB
/
Copy pathdev.js
File metadata and controls
54 lines (44 loc) · 1.22 KB
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
const Webpack = require('webpack');
const WebpackDevServer = require('webpack-dev-server');
const config = require('./webpack.config');
function clearConsole() {
process.stdout.write(process.platform === 'win32' ? '\x1B[2J\x1B[0f' : '\x1B[2J\x1B[3J\x1B[H');
}
clearConsole();
const compiler = Webpack(config);
compiler.hooks.invalid.tap('invalid', () => {
clearConsole();
console.log('Compiling...');
});
const devServer = new WebpackDevServer(compiler, config.devServer);
devServer.listen(9000, 'localhost', err => {
if (err) {
console.log('err', err);
}
});
// const watching = compiler.watch({}, (err, stats) => {
// console.clear();
// if (err) {
// console.error(err.stack || err);
// if (err.details) {
// console.error(err.details);
// }
// return;
// }
// console.log(stats.toJson('minimal'));
// });
process.once('SIGUSR2', function () {
console.log('shutting down...');
const killProcess = () => {
console.log('Killing process!');
process.kill(process.pid, 'SIGUSR2');
};
if (typeof devServer !== 'undefined' && devServer.close) {
devServer.close(() => {
console.log('Webpack watch closed!');
killProcess();
});
} else {
killProcess();
}
});