Skip to content

Commit d2f6a06

Browse files
committed
完善 ip 获取
1 parent 91fdd5f commit d2f6a06

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

_tasks/plugins/TmTIndex.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,7 @@
33
*/
44
var fs = require('fs'),
55
path = require('path'),
6-
os = require('os');
7-
8-
var getIp = function () {
9-
var platform = os.platform();
10-
var interfaces = os.networkInterfaces();
11-
var IPv4 = '127.0.0.1';
12-
13-
if (platform === 'win32') {
14-
var addressMes = interfaces['本地连接'] || interfaces['无线网络连接'];
15-
if (addressMes && addressMes.length) {
16-
for (var i = 0; i < addressMes.length; i++) {
17-
if (addressMes[i]['family'] && addressMes[i]['family'] === 'IPv4') {
18-
IPv4 = addressMes[i]['address'];
19-
break;
20-
}
21-
}
22-
}
23-
} else {
24-
for (var key in interfaces) {
25-
interfaces[key].forEach(function (details) {
26-
if (details.family == 'IPv4' && key == 'en0') {
27-
IPv4 = details.address;
28-
}
29-
});
30-
}
31-
}
32-
33-
return IPv4;
34-
};
6+
localIp = require('quick-local-ip');
357

368
module.exports = function (config) {
379
var html = [
@@ -58,7 +30,7 @@ module.exports = function (config) {
5830
tmpHtml = '',
5931
length = '/dev/html/'.length,
6032
collector = listdir('./dev/html'),
61-
ip = getIp();
33+
ip = localIp.getLocalIP4();
6234

6335

6436
showdir(collector, 0);

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"dependencies": {
55
"autoprefixer": "^6.3.3",
66
"browser-sync": "^2.11.1",
7+
"crypto-md5": "^1.0.0",
78
"del": "^2.2.0",
89
"gulp": "git://github.com/gulpjs/gulp#4.0",
910
"gulp-cssnano": "^2.1.1",
@@ -29,10 +30,10 @@
2930
"lodash": "^4.5.1",
3031
"postcss-pxtorem": "^3.3.1",
3132
"posthtml-px2rem": "^0.0.3",
33+
"quick-local-ip": "^1.0.7",
3234
"rc": "^1.1.6",
3335
"rd": "^0.0.2",
34-
"tmt-ejs-helper": "^0.0.1",
35-
"crypto-md5": "^1.0.0"
36+
"tmt-ejs-helper": "^0.0.1"
3637
},
3738
"description": "A f2e project workflow based on Gulp",
3839
"repository": {
@@ -57,4 +58,4 @@
5758
},
5859
"homepage": "https://github.com/weixin/tmt-workflow",
5960
"readmeFilename": "README.md"
60-
}
61+
}

0 commit comments

Comments
 (0)