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
55
56
57
58
59
60
61
62
63
64
const { chalk, clipboardy, address } = require('@umijs/utils');
class DevCompileDonePlugin {
constructor(opts) {
this.opts = opts;
}
apply(compiler) {
let isFirstCompile = true;
compiler.hooks.done.tap('DevFirstCompileDone', stats => {
if (stats.hasErrors()) {
// make sound
if (process.env.SYSTEM_BELL !== 'none') {
process.stdout.write('\x07');
}
return;
}
if (isFirstCompile) {
const lanIp = address.ip();
const protocol = this.opts.https ? 'https' : 'http';
const hostname =
this.opts.hostname === '0.0.0.0' ? 'localhost' : this.opts.hostname;
const localUrl = `${protocol}://${hostname}:${this.opts.port}`;
const lanUrl = `${protocol}://${lanIp}:${this.opts.port}`;
let copied = '';
try {
clipboardy.writeSync(localUrl);
copied = chalk.dim('(copied to clipboard)');
} catch (e) {
copied = chalk.red(`(copy to clipboard failed)`);
}
console.log(
[
` App running at:`,
` - Local: ${chalk.cyan(localUrl)} ${copied}`,
lanUrl && ` - Network: ${chalk.cyan(lanUrl)}`,
]
.filter(Boolean)
.join('\n'),
);
process.send &&
process.send({
type: 'DONE',
});
isFirstCompile = false;
}
// this.opts.onCompileDone && this.opts.onCompileDone({
// isFirstCompile,
// stats,
// });
if (isFirstCompile) {
isFirstCompile = false;
// process.send({
// type: 'DONE'
// })
}
});
}
}
module.exports = DevCompileDonePlugin;