Vue-cli: Dynamic configuration publicpath

Created on 13 Nov 2018  Â·  9Comments  Â·  Source: vuejs/vue-cli

What problem does this feature solve?

How to configure baseUrl to make__webpack_public_path__ to take effect ? I want to config publicpath dynamically

What does the proposed API look like?

Most helpful comment

Find in https://cli.vuejs.org/config/#baseurl

module.exports = {
  baseUrl: process.env.NODE_ENV === 'production'
    ? '/production-sub-path/'
    : '/'
}

Hope it can help you.

All 9 comments

BaseUrl already does set the public path so I don't understand your request

config publicpath dynamically need to set __webpack_public_path__ in entry file , But the default value of baseurl is ‘/’ , caused the value of __webpack_public_path__ is covered by '/'. So i need to delete the publicPath attribute 。 Then how to delete it ? Or dynamic configuration publicpath in other ways.

So just so that...

Find in https://cli.vuejs.org/config/#baseurl

module.exports = {
  baseUrl: process.env.NODE_ENV === 'production'
    ? '/production-sub-path/'
    : '/'
}

Hope it can help you.

I know. It's my fault. thanks

Hi,

As said in your previous comment, __webpack_public_path__ aims at setting at runtime the public path. With the last solution, publicPath is still set at compile time.

For example, if you build once your app in "production" mode, you may deploy your (artifact) app in several environments, each environment setting his own publicPath as runtime.

The the first problem is to me still unsolved. How to use __webpack_public_path__ with vueJS?

Thanks

How to use webpack_public_path with vue-cli

The webpack docs explain it here - you set it as the very first thing in the entry file.

__webpack_public_path__ = 'whatever/path/you/want/to/set/at/runtime'

There's nothing Vue.js or Vue CLI specific to take into concideration, as far as I can see. Determining at runtime what that public path should be is your responsibility, as Vue CLI can only do it during compile time.

Was this page helpful?
0 / 5 - 0 ratings