mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 00:27:21 +02:00
feat: able to specify host for dev (e.g: 0.0.0.0)
This commit is contained in:
parent
9965eec798
commit
8c6bc6dd38
2 changed files with 7 additions and 0 deletions
|
@ -53,6 +53,7 @@ program
|
||||||
.command('start [siteDir]')
|
.command('start [siteDir]')
|
||||||
.description('Start development server')
|
.description('Start development server')
|
||||||
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
.option('-p, --port <port>', 'use specified port (default: 3000)')
|
||||||
|
.option('-h, --host <host>', 'use specified host (default: localhost')
|
||||||
.option('-nw, --no-watch <noWatch>', 'disable live reload (default: false)')
|
.option('-nw, --no-watch <noWatch>', 'disable live reload (default: false)')
|
||||||
.action((siteDir = '.', {port, noWatch}) => {
|
.action((siteDir = '.', {port, noWatch}) => {
|
||||||
wrapCommand(start)(path.resolve(siteDir), {port, noWatch});
|
wrapCommand(start)(path.resolve(siteDir), {port, noWatch});
|
||||||
|
|
|
@ -14,6 +14,10 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||||
const load = require('../load');
|
const load = require('../load');
|
||||||
const createClientConfig = require('../webpack/client');
|
const createClientConfig = require('../webpack/client');
|
||||||
|
|
||||||
|
function getHost(reqHost) {
|
||||||
|
return reqHost || 'localhost';
|
||||||
|
}
|
||||||
|
|
||||||
async function getPort(reqPort) {
|
async function getPort(reqPort) {
|
||||||
portfinder.basePort = parseInt(reqPort, 10) || 3000;
|
portfinder.basePort = parseInt(reqPort, 10) || 3000;
|
||||||
const port = await portfinder.getPortPromise();
|
const port = await portfinder.getPortPromise();
|
||||||
|
@ -51,6 +55,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
||||||
|
|
||||||
const port = await getPort(cliOptions.port);
|
const port = await getPort(cliOptions.port);
|
||||||
const hotPort = await getPort(port + 1);
|
const hotPort = await getPort(port + 1);
|
||||||
|
const host = getHost(cliOptions.host);
|
||||||
const {baseUrl} = props;
|
const {baseUrl} = props;
|
||||||
|
|
||||||
// create compiler from generated webpack config
|
// create compiler from generated webpack config
|
||||||
|
@ -85,6 +90,7 @@ module.exports = async function start(siteDir, cliOptions = {}) {
|
||||||
},
|
},
|
||||||
logLevel: 'error',
|
logLevel: 'error',
|
||||||
port,
|
port,
|
||||||
|
host,
|
||||||
add: app => {
|
add: app => {
|
||||||
// serve static files
|
// serve static files
|
||||||
const staticDir = path.resolve(siteDir, 'static');
|
const staticDir = path.resolve(siteDir, 'static');
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue