Skip to content

fix(cli-service): make devBaseUrl work properly in serve command#1405

Merged
yyx990803 merged 3 commits into
vuejs:devfrom
jkzing:baseurl-dev
May 30, 2018
Merged

fix(cli-service): make devBaseUrl work properly in serve command#1405
yyx990803 merged 3 commits into
vuejs:devfrom
jkzing:baseurl-dev

Conversation

@jkzing
Copy link
Copy Markdown
Member

@jkzing jkzing commented May 30, 2018

This PR includes:

  1. Use devBaseUrl as process.env.BASE_URL in development mode.

Previously favicon url would be incorrect with:

<link rel="icon" href="<%= BASE_URL %>favicon.ico">
  1. Make webpack-dev-server use devBaseUrl as publicPath

Previously devBaseUrl only changes publicPath in webpack config, which is not enough because the dev server is not serving files in that way...

There still is a issue here, that if we have a vue.config.js like:

module.exports = {
  devBaseUrl: '/foo/'
}

When accessing localhost:8080 without any additional path, historyApiFallback won't be triggered. So that dev server will act like been accessing localhost:8080/index.html, which is the original file (public/index.html) because dev server is serving public folder with contentBase ...

@jkzing
Copy link
Copy Markdown
Member Author

jkzing commented May 30, 2018

🤔, I want to ask why do we need devBaseUrl at all? User can decide what the baseUrl is in config file like:

module.exports = {
  baseUrl: process.env.NODE_ENV === 'production'
    ? 'https://some.cdn.com/'
    : '/'
}

@yyx990803
Copy link
Copy Markdown
Member

@jkzing that's a good point - I've merged the two options in a9e1286

@jkzing jkzing deleted the baseurl-dev branch May 30, 2018 15:12
@adinvadim
Copy link
Copy Markdown

But how can I set devBaseUrl from plugin generator?

api.extendPackage({
  baseUrl: process.env.NODE_ENV === 'production' ? '/static' : '/',
})

now this code isn't the same as this:

api.extendPackage({
  baseUrl: '/static',
  devBaseUrl: '/',
})

@jkzing
Copy link
Copy Markdown
Member Author

jkzing commented Jun 6, 2018

@adinvadim api.extendPackage is to extend the package.json, in which process.env is not available.

@adinvadim
Copy link
Copy Markdown

@jkzing
Oops, I mean

api.extendPackage({
  vue: {
    baseUrl: process.env.NODE_ENV === 'production' ? '/static' : '/',
  }
})

It's to extend the vue.config.js.

This code will execute only on plugin generating. That's why we get in vue.config.js

...
baseUrl: '/'

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

Successfully merging this pull request may close these issues.

3 participants