Skip to content

About baseUrl option #4962

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
EthianWong opened this issue Dec 14, 2019 · 4 comments
Closed

About baseUrl option #4962

EthianWong opened this issue Dec 14, 2019 · 4 comments

Comments

@EthianWong
Copy link

Version

4.1.1

Reproduction link

https://github.com/vuejs/vue-cli

Environment info

System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i5-8259U CPU @ 2.30GHz
  Binaries:
    Node: 10.17.0 - ~/.nvm/versions/node/v10.17.0/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 6.11.3 - ~/.nvm/versions/node/v10.17.0/bin/npm
  Browsers:
    Chrome: 79.0.3945.79
    Firefox: 71.0
    Safari: 13.0.2
  npmPackages:
    @vue/babel-helper-vue-jsx-merge-props:  1.0.0 
    @vue/babel-plugin-transform-vue-jsx:  1.1.2 
    @vue/babel-preset-app:  4.1.1 
    @vue/babel-preset-jsx:  1.1.2 
    @vue/babel-sugar-functional-vue:  1.1.2 
    @vue/babel-sugar-inject-h:  1.1.2 
    @vue/babel-sugar-v-model:  1.1.2 
    @vue/babel-sugar-v-on:  1.1.2 
    @vue/cli-overlay:  4.1.1 
    @vue/cli-plugin-babel: ^4.1.0 => 4.1.1 
    @vue/cli-plugin-eslint: ^4.1.0 => 4.1.1 
    @vue/cli-plugin-router: ^4.1.0 => 4.1.1 
    @vue/cli-plugin-typescript: ^4.1.0 => 4.1.1 
    @vue/cli-plugin-vuex: ^4.1.0 => 4.1.1 
    @vue/cli-service: ^4.1.0 => 4.1.1 
    @vue/cli-shared-utils:  4.1.1 
    @vue/component-compiler-utils:  3.1.0 
    @vue/eslint-config-prettier: ^5.0.0 => 5.1.0 
    @vue/eslint-config-typescript: ^4.0.0 => 4.0.0 
    @vue/preload-webpack-plugin:  1.1.1 
    @vue/web-component-wrapper:  1.2.0 
    eslint-plugin-vue: ^5.0.0 => 5.2.3 
    typescript: ~3.5.3 => 3.5.3 
    vue: ^2.6.10 => 2.6.11 
    vue-class-component: ^7.0.2 => 7.1.0 
    vue-eslint-parser:  5.0.0 
    vue-hot-reload-api:  2.3.4 
    vue-loader:  15.7.2 
    vue-property-decorator: ^8.3.0 => 8.3.0 
    vue-router: ^3.1.3 => 3.1.3 
    vue-style-loader:  4.1.2 
    vue-template-compiler: ^2.6.10 => 2.6.11 
    vue-template-es2015-compiler:  1.9.1 
    vuex: ^3.1.2 => 3.1.2 
  npmGlobalPackages:
    @vue/cli: Not Found

Steps to reproduce

i have a vue.config.js like this:

const publicPath = IS_PROD ? '//qn.cache.***.cn/' : '/'
const assetsDir = IS_PROD ? '${PROJECT_NAME}/admin' : ''

module.exports = {
  publicPath,
  assetsDir
}

What is expected?

<%= BASE_URL %>favicon.ico should output favicon.ico, because i not defined BASE_URL option (when BASE_URL not deprecated)

What is actually happening?

<%= BASE_URL %>favicon.ico output //qn.cache.***.cn/***/admin/favicon.ico


note: I just tried to illustrate the problem with favicon

My company have a common cdn, every project has a identity prefix. in our workflow index.html need self host, but assetsDir will upload to cdn.

when BASE_URL not deprecated, i can set publicPath and assetsDir to get expected.
so, now how can i do?

@EthianWong
Copy link
Author

EthianWong commented Dec 14, 2019

我用中文再复述一遍

我们公司现有的工作流、网关LB等,不支持直接将站点映射为一个CDN路径。所以我们之前的方案是 index.html 会自托管,但为了节省流量,会将 assetsDir 中的内容上传到CDN。我清楚的知道并非所有静态资源都在 assetsDir中 (比如 favicon),但根据我们的情况,这样做可以解决大多数资源文件的流量损耗。

但是现在 baseUrl 被废弃,相同的配置会导致所有项目内的路由 比如 /about 等等,都变为了 cdn 上的路径。所以该怎么样解决这个问题?

@EthianWong
Copy link
Author

@sodatea #4388

@haoqunjiang
Copy link
Member

haoqunjiang commented Dec 14, 2019

但是事实上 publicPath 的工作方式跟原先的 baseUrl 是一模一样的,你可以看一下这个提交里的内容。这个改动只是一个改名,原因是为了避免误解,没有影响功能。 #3143
至于 BASE_URL 这个环境变量,我们是没有动过的。

路由是另一个问题了,参见 #4304 (comment) 应该算是一个 bug,但我暂时没有想到好的办法分别针对这些场景提供合适的默认值。如果你有好的想法的话欢迎提供意见……
暂时的建议是 src/router.js(或 src/router/index.js)里的 base 设置在这种情况下就不要用默认的 process.env.BASE_URL 了,自定义个新的环境变量传过去吧。

@EthianWong
Copy link
Author

好的哦 谢谢么么哒~ @sodatea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants