m0dch3n / vue-cli-plugin-cordova

Vue Cli 3 Cordova Plugin
MIT License
417 stars 63 forks source link

webpack-client/sockjs tries to reach "localhost" instead of network IP #104

Open motla opened 4 years ago

motla commented 4 years ago

Hello!

First of all thank you very much for all your work in this plugin.

This bug is non blocking for development but it causes annoying errors in console. Vue.js uses webpack-client that uses sockjs. For some reason sockjs is not correctly configured and tries to reach device localhost (phone, tablet) instead of the PC server IP on the network.

image

I finally managed to get around this bug by specifying the "public" argument manually in the devServer property of vue.config.js:

vue.config.js

module.exports = {
  devServer: {
    public: "http://192.168.1.63:8080"
  }
}

Note that the same "public" argument of the vue-serve command doesn't have to be set, although it is set anyway from devServer options inside your code.

But it would be much better if you set the public address for webpack automatically, by adding just one line in your runServe function in your main.js (somewhere around line 190), something like:

vue-cli-plugin-cordova/index.js

if(!projectDevServerOptions.public) projectDevServerOptions.public = publicUrl;

I can do a pull request if you like.

Thanks