Skip to content

Commit

Permalink
Set dynamically aboslute public path on 'npm run watch'; fix http/htt…
Browse files Browse the repository at this point in the history
…ps hardcoded in watch.js
  • Loading branch information
Patrick Vézina committed Aug 20, 2016
1 parent b6b0f4b commit d4256ae
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions assets/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"context": "assets",
"entry": {
"main": [
"./scripts/util/public-path.js",
"./scripts/main.js",
"./styles/main.scss"
],
Expand All @@ -13,6 +14,5 @@
"path": "dist",
"publicPath": "/app/themes/sage/dist/"
},
"devUrl": "http://example.dev",
"devPort": 3000
"devUrl": "http://example.dev"
}
8 changes: 8 additions & 0 deletions assets/scripts/util/public-path.js
Original file line number Diff line number Diff line change
@@ -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*/
}
8 changes: 1 addition & 7 deletions watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down
3 changes: 3 additions & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ webpackConfig = {
'window.jQuery': 'jquery',
'Tether': 'tether',
'window.Tether': 'tether'
}),
new webpack.DefinePlugin({
WEBPACK_PUBLIC_PATH: (argv.watch === true) ? JSON.stringify(config.output.publicPath) : false
})
],
postcss: [
Expand Down

0 comments on commit d4256ae

Please sign in to comment.