feat: able to specify host for dev (e.g: 0.0.0.0)

This commit is contained in:
endiliey 2018-08-30 00:29:25 +08:00
parent 9965eec798
commit 8c6bc6dd38
2 changed files with 7 additions and 0 deletions

View file

@ -14,6 +14,10 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
const load = require('../load');
const createClientConfig = require('../webpack/client');
function getHost(reqHost) {
return reqHost || 'localhost';
}
async function getPort(reqPort) {
portfinder.basePort = parseInt(reqPort, 10) || 3000;
const port = await portfinder.getPortPromise();
@ -51,6 +55,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
const port = await getPort(cliOptions.port);
const hotPort = await getPort(port + 1);
const host = getHost(cliOptions.host);
const {baseUrl} = props;
// create compiler from generated webpack config
@ -85,6 +90,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
},
logLevel: 'error',
port,
host,
add: app => {
// serve static files
const staticDir = path.resolve(siteDir, 'static');