Skip to content

Commit 3321a33

Browse files
committed
Now log network address to the console on serve
1 parent b53b858 commit 3321a33

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

webpack.config.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const MiniCssExtractPlugin = require('mini-css-extract-plugin');
44
const CopyPlugin = require('copy-webpack-plugin');
55
const HtmlConfig = require(path.join(__dirname, 'html.config'));
66
const CleanPlugin = require('clean-webpack-plugin');
7+
const os = require('os');
78

89
const deploy = path.join(__dirname, 'deploy');
910

@@ -14,6 +15,30 @@ module.exports = env => {
1415
new MiniCssExtractPlugin({ filename: 'css/game.style.css' }),
1516
new CopyPlugin([{ from: path.join(__dirname + '/static'), to: deploy }])
1617
];
18+
19+
// Get running network information
20+
let networkInfo = os.networkInterfaces();
21+
let ipAddress;
22+
23+
// Depending on operating system the network interface will be named differntly. Check if each exists to find the correct syntax
24+
if (networkInfo.en0){
25+
ipAddress = networkInfo.en0[1].address;
26+
} else if (networkInfo.en7) {
27+
ipAddress = networkInfo.en7[1].address;
28+
} else if (networkInfo['Wi-Fi']){
29+
ipAddress = networkInfo['Wi-Fi'][1].address;
30+
} else if (networkInfo['Ethernet']){
31+
ipAddress = networkInfo['Ethernet'][1].address;
32+
} else if (networkInfo.eth0){
33+
ipAddress = networkInfo.eth0[1].address;
34+
}
35+
36+
if (ipAddress) {
37+
console.log('\x1b[36m%s\x1b[0m', "NETWORK HOST: http://" + ipAddress + ":8080")
38+
} else {
39+
console.log('\x1b[36m%s\x1b[0m', "Unable to find network address");
40+
}
41+
1742
return {
1843
stats: 'errors-only',
1944

0 commit comments

Comments
 (0)