DevCompileDonePlugin.js
2.52 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
function _react() {
const data = _interopRequireDefault(require("react"));
_react = function _react() {
return data;
};
return data;
}
function _utils() {
const data = require("@umijs/utils");
_utils = function _utils() {
return data;
};
return data;
}
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
class DevCompileDonePlugin {
constructor(opts) {
this.opts = void 0;
this.opts = opts;
}
apply(compiler) {
let isFirstCompile = true;
compiler.hooks.done.tap('DevFirstCompileDone', stats => {
var _this$opts$onCompileD, _this$opts2;
if (stats.hasErrors()) {
var _this$opts$onCompileF, _this$opts;
// make sound
if (process.env.SYSTEM_BELL !== 'none') {
process.stdout.write('\x07');
}
(_this$opts$onCompileF = (_this$opts = this.opts).onCompileFail) === null || _this$opts$onCompileF === void 0 ? void 0 : _this$opts$onCompileF.call(_this$opts, {
stats
});
return;
}
if (isFirstCompile) {
const lanIp = _utils().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 {
_utils().clipboardy.writeSync(localUrl);
copied = _utils().chalk.dim('(copied to clipboard)');
} catch (e) {
copied = _utils().chalk.red(`(copy to clipboard failed)`);
}
console.log();
console.log([` App running at:`, ` - Local: ${_utils().chalk.cyan(localUrl)} ${copied}`, lanUrl && ` - Network: ${_utils().chalk.cyan(lanUrl)}`].filter(Boolean).join('\n'));
}
(_this$opts$onCompileD = (_this$opts2 = this.opts).onCompileDone) === null || _this$opts$onCompileD === void 0 ? void 0 : _this$opts$onCompileD.call(_this$opts2, {
isFirstCompile,
stats
});
if (isFirstCompile) {
var _process$send, _process;
isFirstCompile = false;
(_process$send = (_process = process).send) === null || _process$send === void 0 ? void 0 : _process$send.call(_process, {
type: 'DONE'
}); // openBrowser();
}
});
}
}
exports.default = DevCompileDonePlugin;