Search code examples
vue.jswebpackvue-clivue-cli-4

VUE CLI different paths for files in 'public' folder


My application structure is - folder -> frontend - folder with the applications folder -> html -> spa - and this is where I put my app that was built There are 2 folder in 'spa' - assets and static. In static folder there are files from 'frontend -> public'.

Here is the problem I need to add an external script, so i put in head of index.html

<script src="<%= BASE_URL %>static/js/advert.js"></script>

When I have built my app everything is fine, but locally(npm run serve) it has the wrong URL. I tried to play with publicPath in vue.config.js and even set it up correctly by ternary process.env.NODE_ENV === 'production'. On local and built mode the file was fount, but it also has changed all of the routes(links, menu, etc).

Please help me with a work around


Solution

  • So, here is the solution that I figured out.

    In my index.html

    <script src="<%= BASE_URL %><%= NODE_ENV === 'production' ? 'spa/' : ''%>static/js/advert.js"></script>