vuejs / vue-cli

🛠️ webpack-based tooling for Vue.js Development
https://cli.vuejs.org/
MIT License
29.76k stars 6.33k forks source link

Add possibility to force client-side inference of HMR endpoint #3620

Open TobbenTM opened 5 years ago

TobbenTM commented 5 years ago

What problem does this feature solve?

Currently it is not possible to run the vue-cli serve behind a SSL proxy, since the cli hardcodes the HMR endpoint:

https://github.com/vuejs/vue-cli/blob/e48a9569a3a70855cbec38449195f2819bb633fb/packages/%40vue/cli-service/lib/commands/serve.js#L102-L115

Ideally, the HMR requests would also be routed through the proxy, eliminating the need for any additional configuration of vue-cli (adding SSL certificates, etc).

As per the webpack documentation (https://webpack.js.org/configuration/dev-server/#devserverpublic), by default the client will guess the HMR endpoint based in window.location, which would solve this issue. However, there is no way to avoid the above mentioned hardcoding unless we're running the cli in a container, which is not really a solution.

A common use-case for this is how ASP.Net now does SPA integration; they proxy the SPA content to the actual framework dev servers (directly to create-react-app, etc). A Vue.js implementation of this has been made (https://github.com/EEParker/aspnetcore-vueclimiddleware), but it cannot alter the HMR endpoint without also modifying the dev server endpoint, which results in already occupied ports. The closest solution today is to edit the vue configuration to match each devs environment with something like:

module.exports = {
    devServer: {
        public: 'https://localhost:44393/'
    }
};

What does the proposed API look like?

Update vue.config.js with additional option:

module.exports = {
    devServer: {
        clientsidePublicInference: true
    }
}

Would be nice if a command line parameter would also be available, or environment variables, so tools like the above mentioned "aspnetcore-vueclimiddleware" can set this option without modifying configuration.

vue-bot commented 5 years ago

Hello, your issue has been closed because it does not conform to our issue requirements. In order to ensure every issue provides the necessary information for us to investigate, we require the use of the Issue Helper when creating new issues. Thank you!

TobbenTM commented 5 years ago

@LinusBorg Seems like @vue-bot didn't recognize the issue template, do I need to create a new issue, or can you open this one? :)