Skip to content

Commit

Permalink
fix: Ensure devServer info message uses actual devServer config
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Jan 7, 2023
1 parent d8a2d69 commit c9a0561
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 12 deletions.
1 change: 0 additions & 1 deletion packages/cli/src/commands/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ exports.build = async function buildCommand(src, argv) {
argv.src = src || argv.src;
// add `default:true`s, `--no-*` disables
argv.prerender = toBool(argv.prerender);
argv.production = toBool(argv.production);

let cwd = resolve(argv.cwd);

Expand Down
8 changes: 6 additions & 2 deletions packages/cli/src/commands/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ exports.watch = async function watchCommand(src, argv) {
argv.refresh = argv.rhl;
}
argv.src = src || argv.src;
argv.production = false;
if (argv.sw) {
argv.sw = toBool(argv.sw);
}
Expand All @@ -22,9 +21,14 @@ exports.watch = async function watchCommand(src, argv) {
// and the current directory differ.
require('dotenv').config({ path: resolve(cwd, '.env') });

argv.https = toBool(process.env.HTTPS || argv.https);
argv.host = process.env.HOST || argv.host;
if (argv.host === '0.0.0.0' && process.platform === 'win32') {
argv.host = 'localhost';
}
argv.port = await determinePort(argv.port);

if (argv.https || process.env.HTTPS) {
if (argv.https) {
let { key, cert, cacert } = argv;
if (key && cert) {
argv.https = { key, cert, ca: cacert };
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/lib/webpack/run-webpack.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,12 @@ async function devBuild(env) {

compiler.hooks.done.tap('CliDevPlugin', stats => {
let devServer = config.devServer;
let protocol = process.env.HTTPS || devServer.https ? 'https' : 'http';
let host = process.env.HOST || devServer.host || 'localhost';
if (host === '0.0.0.0' && process.platform === 'win32') {
host = 'localhost';
}
let serverAddr = `${protocol}://${host}:${bold(env.port)}`;
let localIpAddr = `${protocol}://${ip.address()}:${bold(env.port)}`;
let protocol = devServer.https ? 'https' : 'http';

let serverAddr = `${protocol}://${devServer.host}:${bold(
devServer.port
)}`;
let localIpAddr = `${protocol}://${ip.address()}:${bold(devServer.port)}`;

if (stats.hasErrors()) {
process.stdout.write(red('Build failed!\n\n'));
Expand Down Expand Up @@ -232,6 +231,7 @@ function stripLoaderFromModuleNames(m) {
}

module.exports = function (env, watch = false) {
env.production = !watch;
env.isProd = env.production; // shorthand
env.isWatch = !!watch; // use HMR?
env.cwd = resolve(env.cwd || process.cwd());
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/lib/webpack/webpack-client-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ function isDev(env) {
},
https: env.https,
port: env.port,
host: process.env.HOST || env.host || '0.0.0.0',
host: env.host,
allowedHosts: 'all',
historyApiFallback: true,
client: {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports.normalizeTemplatesResponse = function (repos = []) {
};

exports.toBool = function (val) {
return val === void 0 || (val === 'false' ? false : val);
return val !== void 0 && val !== false && !/false|0/.test(val);
};

exports.esmImport = require('esm')(module);
Expand Down
1 change: 1 addition & 0 deletions packages/cli/tests/lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ exports.build = async function (cwd, options, installNodeModules = false) {
src: 'src',
dest: 'build',
config: 'preact.config.js',
prerender: true,
prerenderUrls: 'prerender-urls.json',
'inline-css': true,
};
Expand Down

0 comments on commit c9a0561

Please sign in to comment.