1

Our vue application has to be deployed in a web server in a relative path...something like student.com/myvueapp/

so in my vue app , i put public path as myvueapp

and in vue.config.js :

 module.exports = {
      publicPath: '/myvueapp/'
    }

It works in the subpath , when i do vue-cli-service serve .But when i do build and use the assets ,it doesn't work. I I went to dist directory after building and ran python -m SimpleHTTPServer 8000 it fails.

How should i fix it ? should i set some other properties other than public path? I put it into our dev server nginx , but there also it doesn't work.

4
  • 1
    what are you using as server? Commented Jul 25, 2019 at 22:38
  • Nginx in DEV environment. I am curious why doesnt it work in local Commented Jul 25, 2019 at 22:39
  • try this using node Commented Jul 25, 2019 at 22:40
  • npmjs.com/package/static-server I tried this..it doesnt work when publicPath is specified and when i use build Commented Jul 25, 2019 at 22:48

1 Answer 1

0

The build task will only build your app's root directory. The paths within the file will be correct for your configured publicPath though, eg

<!-- in dist/index.html -->
<script src=/myvueapp/js/app.0fcf91de.js></script>

The idea is that you take the contents of your dist folder and deploy it to $DOCUMENT_ROOT/myvueapp/ on your production HTTP server.

For example, if your NGINX config has

root /usr/share/nginx/html;

you would create the directory /usr/share/nginx/html/myvueapp and copy the contents of dist into that.


If you're trying to run it locally, you'll still need to manually create a folder (or symbolic link) for your publicPath.

# in some directory

# create a symlink
ln -s path/to/your/app/dist myvueapp
# or create a real folder, eg
# mkdir myvueapp && cp -a path/to/your/app/dist/* myvueapp/

# start your server
python -m SimpleHTTPServer

then open http://localhost:8000/myvueapp/.

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

4 Comments

What all things should i do in nginx
@Janier I've added an nginx example
I tried it..only difference is i have to start the server outside the directory..so if i have mydir/myvueapp ... I have to be in mydir and start the webserver..is that right?
That's right. Your web server's document root (the local filesystem path corresponding to /) must have relative access to myvueapp

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.