-
Notifications
You must be signed in to change notification settings - Fork 0
/
metro.config.js
58 lines (57 loc) · 1.31 KB
/
metro.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
48
49
50
51
52
53
54
55
56
57
58
/**
* Metro configuration for React Native
* https://github.com/facebook/react-native
*
* @format
*/
const os = require('os');
/*
获取本机IP
*/
function getIPAdressArr() {
let localIPAddress = [];
let interfaces = os.networkInterfaces();
for (let devName in interfaces) {
let iface = interfaces[devName];
for (let i = 0; i < iface.length; i++) {
let alias = iface[i];
if (
alias.family === 'IPv4' &&
alias.address !== '127.0.0.1' &&
!alias.internal
) {
localIPAddress.push(alias.address);
}
}
}
return localIPAddress;
}
module.exports = {
resolver: {
sourceExts: ['js', 'json', 'ts', 'tsx', 'jsx'],
},
transformer: {
getTransformOptions: async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: false,
},
}),
},
server: {
/* server options */
port: 8081,
enhanceMiddleware: (Middleware, Server) => {
let ips = getIPAdressArr();
let port =
(Server._config && Server._config && Server._config.server.port) || '';
console.log('\nMetro server host:port');
for (let i = 0; i < ips.length; i++) {
const ip = ips[i];
console.log(`${i}. ${ip}:${port}`);
}
console.log('\n');
return Middleware;
},
},
};