From c5b7cc54e9bfceda7d48b1f15bcf064a0d96c07d Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 19 Jan 2017 09:41:38 +0000 Subject: [PATCH] Use webpack_port file if it exists --- config/environments/development.rb | 4 ++++ config/webpack.config.js | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/config/environments/development.rb b/config/environments/development.rb index 168c434f261..f8cf196bc7c 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -1,4 +1,6 @@ Rails.application.configure do + WEBPACK_DEV_PORT = `cat ../webpack_port 2>/dev/null || echo '3808'`.to_i + # Settings specified here will take precedence over those in config/application.rb # In the development environment your application's code is reloaded on @@ -24,6 +26,8 @@ Rails.application.configure do # Enable webpack dev server config.webpack.dev_server.enabled = true + config.webpack.dev_server.port = WEBPACK_DEV_PORT + config.webpack.dev_server.manifest_port = WEBPACK_DEV_PORT # Do not compress assets config.assets.compress = false diff --git a/config/webpack.config.js b/config/webpack.config.js index 762147e8b06..bddd181b452 100644 --- a/config/webpack.config.js +++ b/config/webpack.config.js @@ -1,5 +1,6 @@ 'use strict'; +var fs = require('fs'); var path = require('path'); var webpack = require('webpack'); var StatsPlugin = require('stats-webpack-plugin'); @@ -10,7 +11,13 @@ var IS_DEV_SERVER = process.argv[1].indexOf('webpack-dev-server') !== -1; var ROOT_PATH = path.resolve(__dirname, '..'); // must match config.webpack.dev_server.port -var DEV_SERVER_PORT = 3808; +var DEV_SERVER_PORT; + +try { + DEV_SERVER_PORT = parseInt(fs.readFileSync('../webpack_port'), 10); +} catch (e) { + DEV_SERVER_PORT = 3808; +} var config = { context: path.join(ROOT_PATH, 'app/assets/javascripts'),