vuejs / vue-cli

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

CDN Address not working in baseUrl #2380

Open AzaZPPL opened 6 years ago

AzaZPPL commented 6 years ago

Version

3.0.1

Reproduction link

https://github.com/yangmingshan/vue-cli-issue

Node and OS info

Node: 10.9.0 / npm 6.4.0 / MacOS 10.13.6

Steps to reproduce

  1. Set baseUrl in vue.config.js to a CDN url.
  2. Run npm run serve
  3. URL is now set to: http://localhost:8080/https://my.cdn.com/

What is expected?

URL should be set to https://my.cdn.com/

What is actually happening?

Url is set to http://localhost:8080/https://my.cdn.com/


This issue #1545 was fixed with commit 1195aee. In the later commit 1e7fa2c the fix got removed.

zhougonglai commented 6 years ago

i think it fix on the vue/cli-service 3.0.1

aprilandjan commented 6 years ago

This is not fixed for now. And the commit 1195aee I think it is not the solution. The document here https://cli.vuejs.org/config/#baseurl about baseurl cannot help eather.

I tried to hack into /node_modules/@vue/cli-service/ in my local machine, change the options.baseUrl into my CDN address (which is used by webpack as output.publicPath, also assetsPublicPath config in previous vue-cli template) at https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/config/base.js#L37, and then comment the line which throw error at https://github.com/vuejs/vue-cli/blob/dev/packages/%40vue/cli-service/lib/util/validateWebpackConfig.js#L32. Then I build my project, upload to remote host and it finally worked.

Do we really do not need assetsPublicPath anymore in Vue-Cli v3 ? I doubted.

rushairer commented 6 years ago

new Router({ mode: process.env.BASE_URL ? 'history' : 'hash', base: '/', routes: routes })

set the 'base' to '/'

@AzaZPPL @aprilandjan

aprilandjan commented 6 years ago

@rushairer Thanks bro you remind me that the vue-router base could be configured manually, I almost forgot that - -. So I only need to define my own enviroment variable as router base in webpack config, and this could be solved easily. I just made it tooo complicated, lol.

Maybe the template project with router could be improved to prevent such problems, or the documention could cover this situation. Still I think it is necessary to discriminate assetsPublicPath to baseUrl

rushairer commented 6 years ago

@aprilandjan You are welcome. I met the same problem with you yesterday, and then I saw the 'base:/' unconsciously. 😂