2

My vue project is completed. When I run script 'npm run build',which is 'vue-cli-service build', I can get a pack of output files. However in index.html file, all js and css files' path are not right. for example:

<script src=js/chunk-vendors.40fba41b.js>

Correct one should be:

<script src="./js/chunk-vendors.40fba41b.js">

I googled a lot. Some said to modify webpack's config, which I found out impossible since vue-cli3 does not provide such config file. Some said it can be done by adding baseurl in vue.config.js file like this:

module.exports = {
    baseUrl: "./",
}

When I set baseUrl as './', the problem remains. When I change baseUrl to "somecode/", the output files would be:

<script src=somecode/js/chunk-vendors.40fba41b.js>

I am really confused by it. Why and how to fix this problem? Thanks in advance.

2
  • Did you use history.pushState or build a multi page app with the page option because relative baseUrl has some limitation. cf: cli.vuejs.org/config/#baseurl Commented Nov 30, 2018 at 17:14
  • @Jérôme I only use vue-router’s push function. Neither do I use html5’s pushstate nor page. Commented Dec 1, 2018 at 4:20

1 Answer 1

3

set baseurl as "././"

full vue.config.js file:

module.exports = {
    baseUrl: "././",
}

reference: https://github.com/vuejs/vue-cli/issues/2595#issuecomment-424570482

Sign up to request clarification or add additional context in comments.

1 Comment

Note that (since Vue CLI3.3), baseUrl has been deprecated in favor of publicPath.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.