From fe322c686b722f842ba9a10538e3f0e7a41e6167 Mon Sep 17 00:00:00 2001 From: Chunpeng Huo Date: Tue, 5 Nov 2019 09:46:07 +1100 Subject: [PATCH] fix(webpack): deal with host option before webpack config MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because webpack-dev-server fills up some default value to webpack config. It adds host with value localhost when user didn’t explicitly set in command line. Ref: https://discourse.aurelia.io/t/changing-platform-host-in-aurelia-json-doesnt-change-the-host-ip/3043/10?u=huochunpeng --- skeleton/webpack/aurelia_project/tasks/run.ext | 10 ++++++++++ skeleton/webpack/webpack.config.js | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/skeleton/webpack/aurelia_project/tasks/run.ext b/skeleton/webpack/aurelia_project/tasks/run.ext index 83798b8c4..89574aa5a 100644 --- a/skeleton/webpack/aurelia_project/tasks/run.ext +++ b/skeleton/webpack/aurelia_project/tasks/run.ext @@ -5,6 +5,7 @@ import kill from 'tree-kill'; // @if feat.typescript import * as kill from 'tree-kill'; // @endif +import { platform } from '../aurelia.json'; const npm = new NPM(); @@ -17,7 +18,9 @@ function run() { // Cleanup --env prod to --env.production // for backwards compatibility function cleanArgs(args) { + let host; const cleaned = []; + for (let i = 0, ii = args.length; i < ii; i++) { if (args[i] === '--env' && i < ii - 1) { const env = args[++i].toLowerCase(); @@ -26,10 +29,17 @@ function cleanArgs(args) { } else if (env.startsWith('test')) { cleaned.push('--tests'); } + } else if (args[i] === '--host' && i < ii -1) { + host = args[++i]; } else { cleaned.push(args[i]); } } + + // Deal with --host before webpack-dev-server calls webpack config. + // Because of https://discourse.aurelia.io/t/changing-platform-host-in-aurelia-json-doesnt-change-the-host-ip/3043/10?u=huochunpeng + if (!host) host = platform.host; + if (host) cleaned.push('--host', host); return cleaned; } diff --git a/skeleton/webpack/webpack.config.js b/skeleton/webpack/webpack.config.js index 6bb53233f..6d88027e2 100644 --- a/skeleton/webpack/webpack.config.js +++ b/skeleton/webpack/webpack.config.js @@ -210,7 +210,7 @@ module.exports = ({ production } = {}, {extractCss, analyze, tests, hmr, port, h historyApiFallback: true, hot: hmr || project.platform.hmr, port: port || project.platform.port, - host: host || project.platform.host + host: host }, devtool: production ? 'nosources-source-map' : 'cheap-module-eval-source-map', module: {