Laravel-mix: Could we make the port for HMR editable?

Created on 14 Jan 2017  路  10Comments  路  Source: JeffreyWay/laravel-mix

I'm talking about this line. Sometimes my webserver is already running on localhost:8080 and I'd like to be able to configure this to run on a different port when I need it to.

Most helpful comment

Yes, we'll make it configurable soon.

All 10 comments

Yes, we'll make it configurable soon.

Similar to the webpack template, could this be done with ENV var first and config later (with default to 8080); https://github.com/vuejs-templates/webpack/blob/ff9c817aef660edce82f900d91d1b730382f1e1c/template/build/dev-server.js#L14

So we could do something like PORT=3000 npm run dev to set the port to 3000. That would make it easy to switch ports on the fly :)

And preferably also the app url, if it's different then localhost (eg. remote server). You can run the dev server on different port/host already, but fails when new files are pushed; yarn run hot -- --port=3000 --host=0.0.0.0

I am attempting to implement the same functionality (I believe). I currently set the --port option to 7770. I can then pull my files from 7770. However, HMR seems to be broken.

My cli output looks like:

Project is running at http://localhost:7770/
webpack output is served from http://localhost:8080/
404s will fallback to /index.html

On update, I see

GET http://localhost:8080/0faa46fc8c8619784541.hot-update.json net::ERR_CONNECTION_REFUSED

I believe this could be remedied by changing the hmr port (though if you suspect otherwise, please let me know). I've attempted to manually set the "port" property on the devServer object in webpack.config.js in the mix source code but it didn't seem to affect which port was used.

Workaround for setting host/port in Laravel-Mix 1.x:

put the following code in your webpack.mix.js:

if (Config.hmr) {
  mix.webpackConfig({
    output: {
      publicPath: 'http://localhost:8082/'
    }
  })
}

And add --port 8082 to your webpack-dev-server call (likely in your package.json)

I haven't checked how webpack-merge merges nested objects. If webpackConfig.output gets overwritten during merge this might cause side effects. This works fine for me though.

can this get some light?


just want to bump this thread

@lorvent This probably fixes it

https://github.com/JeffreyWay/laravel-mix/pull/1246

yes, that fixes it.

@lorvent Just waiting on @JeffreyWay to look over it

Done.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rlewkowicz picture rlewkowicz  路  3Comments

stefensuhat picture stefensuhat  路  3Comments

mstralka picture mstralka  路  3Comments

Micaso picture Micaso  路  3Comments

Cheddam picture Cheddam  路  3Comments