Skip to content

Commit a526a00

Browse files
authored
fix: Ensure devServer info message uses actual devServer config (#1770)
* fix: Ensure devServer info message uses actual devServer config * docs: Adding changeset
1 parent d8a2d69 commit a526a00

File tree

7 files changed

+21
-12
lines changed

7 files changed

+21
-12
lines changed

.changeset/curvy-clouds-shake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'preact-cli': patch
3+
---
4+
5+
Fix for devServer info output possibly not matching up against devServer config

packages/cli/src/commands/build.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ exports.build = async function buildCommand(src, argv) {
88
argv.src = src || argv.src;
99
// add `default:true`s, `--no-*` disables
1010
argv.prerender = toBool(argv.prerender);
11-
argv.production = toBool(argv.production);
1211

1312
let cwd = resolve(argv.cwd);
1413

packages/cli/src/commands/watch.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ exports.watch = async function watchCommand(src, argv) {
99
argv.refresh = argv.rhl;
1010
}
1111
argv.src = src || argv.src;
12-
argv.production = false;
1312
if (argv.sw) {
1413
argv.sw = toBool(argv.sw);
1514
}
@@ -22,9 +21,14 @@ exports.watch = async function watchCommand(src, argv) {
2221
// and the current directory differ.
2322
require('dotenv').config({ path: resolve(cwd, '.env') });
2423

24+
argv.https = toBool(process.env.HTTPS || argv.https);
25+
argv.host = process.env.HOST || argv.host;
26+
if (argv.host === '0.0.0.0' && process.platform === 'win32') {
27+
argv.host = 'localhost';
28+
}
2529
argv.port = await determinePort(argv.port);
2630

27-
if (argv.https || process.env.HTTPS) {
31+
if (argv.https) {
2832
let { key, cert, cacert } = argv;
2933
if (key && cert) {
3034
argv.https = { key, cert, ca: cacert };

packages/cli/src/lib/webpack/run-webpack.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@ async function devBuild(env) {
2323

2424
compiler.hooks.done.tap('CliDevPlugin', stats => {
2525
let devServer = config.devServer;
26-
let protocol = process.env.HTTPS || devServer.https ? 'https' : 'http';
27-
let host = process.env.HOST || devServer.host || 'localhost';
28-
if (host === '0.0.0.0' && process.platform === 'win32') {
29-
host = 'localhost';
30-
}
31-
let serverAddr = `${protocol}://${host}:${bold(env.port)}`;
32-
let localIpAddr = `${protocol}://${ip.address()}:${bold(env.port)}`;
26+
let protocol = devServer.https ? 'https' : 'http';
27+
28+
let serverAddr = `${protocol}://${devServer.host}:${bold(
29+
devServer.port
30+
)}`;
31+
let localIpAddr = `${protocol}://${ip.address()}:${bold(devServer.port)}`;
3332

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

234233
module.exports = function (env, watch = false) {
234+
env.production = !watch;
235235
env.isProd = env.production; // shorthand
236236
env.isWatch = !!watch; // use HMR?
237237
env.cwd = resolve(env.cwd || process.cwd());

packages/cli/src/lib/webpack/webpack-client-config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ function isDev(env) {
351351
},
352352
https: env.https,
353353
port: env.port,
354-
host: process.env.HOST || env.host || '0.0.0.0',
354+
host: env.host,
355355
allowedHosts: 'all',
356356
historyApiFallback: true,
357357
client: {

packages/cli/src/util.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ exports.normalizeTemplatesResponse = function (repos = []) {
5353
};
5454

5555
exports.toBool = function (val) {
56-
return val === void 0 || (val === 'false' ? false : val);
56+
return val !== void 0 && val !== false && !/false|0/.test(val);
5757
};
5858

5959
exports.esmImport = require('esm')(module);

packages/cli/tests/lib/cli.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ exports.build = async function (cwd, options, installNodeModules = false) {
1919
src: 'src',
2020
dest: 'build',
2121
config: 'preact.config.js',
22+
prerender: true,
2223
prerenderUrls: 'prerender-urls.json',
2324
'inline-css': true,
2425
};

0 commit comments

Comments
 (0)