Skip to content

Commit

Permalink
fix(webpack): deal with host option before webpack config
Browse files Browse the repository at this point in the history
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
  • Loading branch information
3cp committed Nov 4, 2019
1 parent c246d66 commit fe322c6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions skeleton/webpack/aurelia_project/tasks/run.ext
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion skeleton/webpack/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down

0 comments on commit fe322c6

Please sign in to comment.