Skip to content

Commit fe322c6

Browse files
committed
fix(webpack): deal with host option before webpack config
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
1 parent c246d66 commit fe322c6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

skeleton/webpack/aurelia_project/tasks/run.ext

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import kill from 'tree-kill';
55
// @if feat.typescript
66
import * as kill from 'tree-kill';
77
// @endif
8+
import { platform } from '../aurelia.json';
89

910
const npm = new NPM();
1011

@@ -17,7 +18,9 @@ function run() {
1718
// Cleanup --env prod to --env.production
1819
// for backwards compatibility
1920
function cleanArgs(args) {
21+
let host;
2022
const cleaned = [];
23+
2124
for (let i = 0, ii = args.length; i < ii; i++) {
2225
if (args[i] === '--env' && i < ii - 1) {
2326
const env = args[++i].toLowerCase();
@@ -26,10 +29,17 @@ function cleanArgs(args) {
2629
} else if (env.startsWith('test')) {
2730
cleaned.push('--tests');
2831
}
32+
} else if (args[i] === '--host' && i < ii -1) {
33+
host = args[++i];
2934
} else {
3035
cleaned.push(args[i]);
3136
}
3237
}
38+
39+
// Deal with --host before webpack-dev-server calls webpack config.
40+
// Because of https://discourse.aurelia.io/t/changing-platform-host-in-aurelia-json-doesnt-change-the-host-ip/3043/10?u=huochunpeng
41+
if (!host) host = platform.host;
42+
if (host) cleaned.push('--host', host);
3343
return cleaned;
3444
}
3545

skeleton/webpack/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ module.exports = ({ production } = {}, {extractCss, analyze, tests, hmr, port, h
210210
historyApiFallback: true,
211211
hot: hmr || project.platform.hmr,
212212
port: port || project.platform.port,
213-
host: host || project.platform.host
213+
host: host
214214
},
215215
devtool: production ? 'nosources-source-map' : 'cheap-module-eval-source-map',
216216
module: {

0 commit comments

Comments
 (0)