-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwebpack.dev.babel.js
49 lines (40 loc) · 1.48 KB
/
webpack.dev.babel.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
import * as path from 'path';
import * as os from 'os';
import merge from 'webpack-merge';
import LiveReloadPlugin from 'webpack-livereload-plugin';
import chalk from 'chalk';
import commonConfig from './webpack.common';
const port = process.env.PATTERN_LIB_PORT || 3333;
function getIP() {
const interfaces = os.networkInterfaces();
let interfaceArray = [];
for (let key in interfaces) {
if (interfaces.hasOwnProperty(key)) {
interfaceArray = interfaceArray.concat(interfaces[key]);
}
}
const _interface = interfaceArray.filter(_interface => _interface.family === 'IPv4' && _interface.address !== '127.0.0.1')[0];
return _interface ? _interface.address : 'localhost';
}
const serverSettings = {
devServer: {
contentBase: path.join(__dirname, 'build'),
compress: false,
port,
after: function() {
setTimeout(() => {
console.log(chalk.blue.bold('======================================='));
console.log(chalk.bold.cyan('Server started'));
console.log(`${chalk.bold.cyan('Local:')} ${chalk.bold.green(`http://localhost:${port}`)}`);
console.log(`${chalk.bold.cyan('Remote:')} ${chalk.bold.green(`http://${getIP()}:${port}`)}`);
console.log(chalk.blue.bold('======================================='));
}, 2000);
},
stats: 'errors-only',
headers: {
'Access-Control-Allow-Origin': '*'
}
},
plugins: [new LiveReloadPlugin()]
};
export default merge(commonConfig('development'), serverSettings);