updated npm modules
This commit is contained in:
91
node_modules/webpack-dev-server/bin/webpack-dev-server.js
generated
vendored
91
node_modules/webpack-dev-server/bin/webpack-dev-server.js
generated
vendored
@@ -12,24 +12,21 @@ const debug = require('debug')('webpack-dev-server');
|
||||
const fs = require('fs');
|
||||
const net = require('net');
|
||||
|
||||
const portfinder = require('portfinder');
|
||||
const importLocal = require('import-local');
|
||||
|
||||
const yargs = require('yargs');
|
||||
const webpack = require('webpack');
|
||||
|
||||
const options = require('./options');
|
||||
|
||||
const Server = require('../lib/Server');
|
||||
|
||||
const addEntries = require('../lib/utils/addEntries');
|
||||
const colors = require('../lib/utils/colors');
|
||||
const createConfig = require('../lib/utils/createConfig');
|
||||
const createDomain = require('../lib/utils/createDomain');
|
||||
const createLogger = require('../lib/utils/createLogger');
|
||||
const defaultTo = require('../lib/utils/defaultTo');
|
||||
const findPort = require('../lib/utils/findPort');
|
||||
const getVersions = require('../lib/utils/getVersions');
|
||||
const runBonjour = require('../lib/utils/runBonjour');
|
||||
const status = require('../lib/utils/status');
|
||||
const tryParseInt = require('../lib/utils/tryParseInt');
|
||||
|
||||
let server;
|
||||
|
||||
@@ -73,8 +70,17 @@ yargs.usage(
|
||||
`${getVersions()}\nUsage: https://webpack.js.org/configuration/dev-server/`
|
||||
);
|
||||
|
||||
// webpack-cli@3.3 path : 'webpack-cli/bin/config/config-yargs'
|
||||
let configYargsPath;
|
||||
try {
|
||||
require.resolve('webpack-cli/bin/config/config-yargs');
|
||||
configYargsPath = 'webpack-cli/bin/config/config-yargs';
|
||||
} catch (e) {
|
||||
configYargsPath = 'webpack-cli/bin/config-yargs';
|
||||
}
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
require('webpack-cli/bin/config-yargs')(yargs);
|
||||
// eslint-disable-next-line import/no-dynamic-require
|
||||
require(configYargsPath)(yargs);
|
||||
|
||||
// It is important that this is done after the webpack yargs config,
|
||||
// so it overrides webpack's version info.
|
||||
@@ -83,8 +89,17 @@ yargs.options(options);
|
||||
|
||||
const argv = yargs.argv;
|
||||
|
||||
// webpack-cli@3.3 path : 'webpack-cli/bin/utils/convert-argv'
|
||||
let convertArgvPath;
|
||||
try {
|
||||
require.resolve('webpack-cli/bin/utils/convert-argv');
|
||||
convertArgvPath = 'webpack-cli/bin/utils/convert-argv';
|
||||
} catch (e) {
|
||||
convertArgvPath = 'webpack-cli/bin/convert-argv';
|
||||
}
|
||||
// eslint-disable-next-line import/no-extraneous-dependencies
|
||||
const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {
|
||||
// eslint-disable-next-line import/no-dynamic-require
|
||||
const config = require(convertArgvPath)(yargs, argv, {
|
||||
outputFilename: '/bundle.js',
|
||||
});
|
||||
|
||||
@@ -93,6 +108,15 @@ const config = require('webpack-cli/bin/convert-argv')(yargs, argv, {
|
||||
// we should use portfinder.
|
||||
const DEFAULT_PORT = 8080;
|
||||
|
||||
// Try to find unused port and listen on it for 3 times,
|
||||
// if port is not specified in options.
|
||||
// Because NaN == null is false, defaultTo fails if parseInt returns NaN
|
||||
// so the tryParseInt function is introduced to handle NaN
|
||||
const defaultPortRetry = defaultTo(
|
||||
tryParseInt(process.env.DEFAULT_PORT_RETRY),
|
||||
3
|
||||
);
|
||||
|
||||
function processOptions(config) {
|
||||
// processOptions {Promise}
|
||||
if (typeof config.then === 'function') {
|
||||
@@ -106,31 +130,12 @@ function processOptions(config) {
|
||||
}
|
||||
|
||||
const options = createConfig(config, argv, { port: DEFAULT_PORT });
|
||||
|
||||
portfinder.basePort = DEFAULT_PORT;
|
||||
|
||||
if (options.port != null) {
|
||||
startDevServer(config, options);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
portfinder.getPort((err, port) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
options.port = port;
|
||||
|
||||
startDevServer(config, options);
|
||||
});
|
||||
startDevServer(config, options);
|
||||
}
|
||||
|
||||
function startDevServer(config, options) {
|
||||
const log = createLogger(options);
|
||||
|
||||
addEntries(config, options);
|
||||
|
||||
let compiler;
|
||||
|
||||
try {
|
||||
@@ -151,11 +156,6 @@ function startDevServer(config, options) {
|
||||
}).apply(compiler);
|
||||
}
|
||||
|
||||
const suffix =
|
||||
options.inline !== false || options.lazy === true
|
||||
? '/'
|
||||
: '/webpack-dev-server/';
|
||||
|
||||
try {
|
||||
server = new Server(compiler, options, log);
|
||||
} catch (err) {
|
||||
@@ -203,25 +203,26 @@ function startDevServer(config, options) {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
const uri = createDomain(options, server.listeningApp) + suffix;
|
||||
|
||||
status(uri, options, log, argv.color);
|
||||
});
|
||||
});
|
||||
} else if (options.port) {
|
||||
runServer();
|
||||
} else {
|
||||
// only run port finder if no port as been specified
|
||||
findPort(server, DEFAULT_PORT, defaultPortRetry, (err, port) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
options.port = port;
|
||||
runServer();
|
||||
});
|
||||
}
|
||||
|
||||
function runServer() {
|
||||
server.listen(options.port, options.host, (err) => {
|
||||
if (err) {
|
||||
throw err;
|
||||
}
|
||||
|
||||
if (options.bonjour) {
|
||||
runBonjour(options);
|
||||
}
|
||||
|
||||
const uri = createDomain(options, server.listeningApp) + suffix;
|
||||
|
||||
status(uri, options, log, argv.color);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user