forked from artificialsolutions/teneo-web-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.dev.js
executable file
·56 lines (53 loc) · 1.84 KB
/
webpack.dev.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
const webpack = require('webpack');
const path = require('path');
const {merge} = require('webpack-merge');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const baseConfig = require('./webpack.base.js');
require('dotenv')
.config();
const dotenv = require('dotenv')
.config({path: `${__dirname}/.env`});
let devServerOptions = {
static: path.join(__dirname, 'dist'),
compress: true,
port: 9000
};
if (dotenv.parsed.ALLOW_LAN_ON_DEV === "true") {
// Host set to 0.0.0.0 with a public IP to allow for connections over LAN.
process.on('warning', (warning) => {
console.log(warning.stack);
});
process.on('error', (error) => {
console.log(error.stack);
});
const os = require('os');
const networkInterfaces = os.networkInterfaces();
devServerOptions.host = '0.0.0.0';
devServerOptions.port = 9000;
Object.keys(networkInterfaces)
.forEach(function (interfaceName) {
networkInterfaces[interfaceName].forEach(function (networkInterface) {
if ('IPv4' !== networkInterface.family || networkInterface.internal !== false) {
// skip over internal (i.e. 127.0.0.1) and non-ipv4 addresses
return;
}
if (networkInterface.address.startsWith('192.168')) {
devServerOptions.host = networkInterface.address;
console.log('Server on LAN at address: ' + devServerOptions.host);
}
});
});
}
module.exports = merge(baseConfig, {
mode: 'development',
devtool: 'inline-source-map',
devServer: devServerOptions,
plugins: [
new webpack.DefinePlugin({
'process.env': JSON.stringify(dotenv.parsed)
}),
new HtmlWebpackPlugin({
template: './views/index.ejs',
}),
],
});