Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vuejs in production: prefix static path

Tags:

webpack

vue.js

Context

I'm building a VueJS app and I would like to push it in production. I've generated files using npm run build and I've uploaded those on a server (IIS).

I have a lot of other applications on this server and I can't change how it works.

Here is a fake example to help me explain my issue:

mydomain.com/app1 will redirect to a web-app under a folder app1. To add my VueJS project I've created a new folder - lets say vueapp - and I get access it via mydomain.com/vueapp.

The thing is : the static paths generated by vue are not prefixed by vueapp. Paths in index.html are not like I want : I get mydomain.com/static/** instead of mydomaim.com/vueapp/static/** for a vue request.

I would like to tell webpack to prefix index.html's path by something but I can't get it work.

assetsSubDirectory

config/build.js gives us the possibility to change the assets sub directory (which is static by default). So I can set it to vueappPrefix/static but of course, this doesn't work.

  • expected: mydomain.com/vueapp/vueappPrefix/static/*
  • what I get: mydomain.com/vueappPrefix/static

This is obvious.

Of course I can edit index.html by hand or add a script to do it but I would like to know if there is a cleaner way to do this.

Thanks a lot.

like image 939
Clément Flodrops Avatar asked Jul 25 '17 14:07

Clément Flodrops


1 Answers

Changing the assetsPublicPath works for me.

In this case, it'd be:

assetsPublicPath: '/vueapp/'

UPDATE (11/20): To do the same in newer versions of vue-cli, there's an option mentioned in the comments.

like image 57
Luis Orduz Avatar answered Oct 14 '22 13:10

Luis Orduz