Skip to content
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

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

Merged
merged 3 commits into from
May 30, 2018

Conversation

jkzing
Copy link
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
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
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

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
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

@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