From 7623ad0511093372df8a0d2f22bdeae80253e6b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20V=C3=A9zina?= Date: Fri, 26 Aug 2016 13:45:50 -0400 Subject: [PATCH] =?UTF-8?q?Set=20dynamically=20aboslute=20public=20path=20?= =?UTF-8?q?on=20'npm=20run=20watch';=20fix=20http/htt=E2=80=A6=20(#1696)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Set dynamically aboslute public path on 'npm run watch'; fix http/https hardcoded in watch.js * WEBPACK_PUBLIC_PATH fix --- assets/config.json | 1 + assets/scripts/util/public-path.js | 8 ++++++++ watch.js | 8 +------- webpack.config.js | 3 +++ 4 files changed, 13 insertions(+), 7 deletions(-) create mode 100644 assets/scripts/util/public-path.js diff --git a/assets/config.json b/assets/config.json index 88d3ab7..a6edc97 100644 --- a/assets/config.json +++ b/assets/config.json @@ -1,6 +1,7 @@ { "entry": { "main": [ + "./scripts/util/public-path.js", "./scripts/main.js", "./styles/main.scss" ], diff --git a/assets/scripts/util/public-path.js b/assets/scripts/util/public-path.js new file mode 100644 index 0000000..af588c2 --- /dev/null +++ b/assets/scripts/util/public-path.js @@ -0,0 +1,8 @@ +/* globals WEBPACK_PUBLIC_PATH */ + +// Dynamically set absolute public path from current protocol and host +if (WEBPACK_PUBLIC_PATH !== false) { + /* eslint-disable no-undef */ + __webpack_public_path__ = location.protocol + '//' + location.host + WEBPACK_PUBLIC_PATH; + /*eslint-enable no-undef*/ +} diff --git a/watch.js b/watch.js index 95189ff..0a867bf 100644 --- a/watch.js +++ b/watch.js @@ -9,15 +9,9 @@ var webpackConfig = require('./webpack.config'), config = require('./assets/config'); // Internal variables -var host = 'http://localhost', - port = config.devPort || '3000', - compiler; - -webpackConfig.output.publicPath = host + ':' + port + config.output.publicPath; -compiler = webpack(webpackConfig); +var compiler = webpack(webpackConfig); browserSync.init({ - port: port, proxy: { target: config.devUrl, middleware: [ diff --git a/webpack.config.js b/webpack.config.js index 13658fd..ba5de4e 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -191,6 +191,9 @@ webpackConfig = { 'window.jQuery': 'jquery', 'Tether': 'tether', 'window.Tether': 'tether' + }), + new webpack.DefinePlugin({ + WEBPACK_PUBLIC_PATH: (argv.watch === true) ? JSON.stringify(path.join(config.publicPath, dist)) : false }) ], postcss: [