From f47abd85c259ed8608a2d7da7cef09612a97834e Mon Sep 17 00:00:00 2001 From: dolchi21 Date: Fri, 22 Jul 2016 21:45:35 -0300 Subject: [PATCH 1/2] npm start - process.env.PORT support --- config/webpack.config.dev.js | 4 +++- scripts/start.js | 9 +++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index 65b3936ccb8..fd312dd43ff 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -7,6 +7,8 @@ * of patent rights can be found in the PATENTS file in the same directory. */ +var PORT = process.env.PORT || 3000; + var path = require('path'); var autoprefixer = require('autoprefixer'); var webpack = require('webpack'); @@ -32,7 +34,7 @@ var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build module.exports = { devtool: 'eval', entry: [ - require.resolve('webpack-dev-server/client') + '?http://localhost:3000', + require.resolve('webpack-dev-server/client') + '?http://localhost:'+PORT, require.resolve('webpack/hot/dev-server'), path.join(srcPath, 'index') ], diff --git a/scripts/start.js b/scripts/start.js index 2032a526f38..46577f3bbd3 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -8,6 +8,7 @@ */ process.env.NODE_ENV = 'development'; +var PORT = process.env.PORT || 3000; var path = require('path'); var chalk = require('chalk'); @@ -77,7 +78,7 @@ compiler.plugin('done', function (stats) { if (!hasErrors && !hasWarnings) { console.log(chalk.green('Compiled successfully!')); console.log(); - console.log('The app is running at http://localhost:3000/'); + console.log('The app is running at http://localhost:'+PORT+'/'); console.log(); return; } @@ -130,7 +131,7 @@ function openBrowser() { execSync( 'osascript ' + path.resolve(__dirname, './openChrome.applescript') + - ' http://localhost:3000/' + ' http://localhost:'+PORT+'/' ); return; } catch (err) { @@ -139,7 +140,7 @@ function openBrowser() { } // Fallback to opn // (It will always open new tab) - opn('http://localhost:3000/'); + opn('http://localhost:'+PORT+'/'); } new WebpackDevServer(compiler, { @@ -147,7 +148,7 @@ new WebpackDevServer(compiler, { hot: true, // Note: only CSS is currently hot reloaded publicPath: config.output.publicPath, quiet: true -}).listen(3000, 'localhost', function (err, result) { +}).listen(PORT, 'localhost', function (err, result) { if (err) { return console.log(err); } From e1415b409d6dd811f7a57c5c6020440c91a6271f Mon Sep 17 00:00:00 2001 From: dolchi21 Date: Sat, 23 Jul 2016 11:42:24 -0300 Subject: [PATCH 2/2] npm start - process.env.HOST support --- config/webpack.config.dev.js | 3 ++- scripts/start.js | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/config/webpack.config.dev.js b/config/webpack.config.dev.js index fd312dd43ff..12ec9e2b7b0 100644 --- a/config/webpack.config.dev.js +++ b/config/webpack.config.dev.js @@ -8,6 +8,7 @@ */ var PORT = process.env.PORT || 3000; +var HOST = process.env.HOST || 'localhost'; var path = require('path'); var autoprefixer = require('autoprefixer'); @@ -34,7 +35,7 @@ var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build module.exports = { devtool: 'eval', entry: [ - require.resolve('webpack-dev-server/client') + '?http://localhost:'+PORT, + require.resolve('webpack-dev-server/client') + '?http://'+HOST+':'+PORT, require.resolve('webpack/hot/dev-server'), path.join(srcPath, 'index') ], diff --git a/scripts/start.js b/scripts/start.js index 46577f3bbd3..54286bad477 100644 --- a/scripts/start.js +++ b/scripts/start.js @@ -9,6 +9,7 @@ process.env.NODE_ENV = 'development'; var PORT = process.env.PORT || 3000; +var HOST = process.env.HOST || 'localhost'; var path = require('path'); var chalk = require('chalk'); @@ -78,7 +79,7 @@ compiler.plugin('done', function (stats) { if (!hasErrors && !hasWarnings) { console.log(chalk.green('Compiled successfully!')); console.log(); - console.log('The app is running at http://localhost:'+PORT+'/'); + console.log('The app is running at http://'+HOST+':'+PORT+'/'); console.log(); return; } @@ -131,7 +132,7 @@ function openBrowser() { execSync( 'osascript ' + path.resolve(__dirname, './openChrome.applescript') + - ' http://localhost:'+PORT+'/' + ' http://'+HOST+':'+PORT+'/' ); return; } catch (err) { @@ -140,7 +141,7 @@ function openBrowser() { } // Fallback to opn // (It will always open new tab) - opn('http://localhost:'+PORT+'/'); + opn('http://'+HOST+':'+PORT+'/'); } new WebpackDevServer(compiler, { @@ -148,7 +149,7 @@ new WebpackDevServer(compiler, { hot: true, // Note: only CSS is currently hot reloaded publicPath: config.output.publicPath, quiet: true -}).listen(PORT, 'localhost', function (err, result) { +}).listen(PORT, HOST, function (err, result) { if (err) { return console.log(err); }