'Problems deploying Vue project after build on Apache webserver due to wrong relative paths

I have a simple Vue.js project. I ran the command yarn build, then copied all the files inside dist/ folder onto Apache webserver.

When my URL pointed to the generated index.html, nothing appeared. I discovered this was due index.html pointing to the wrong relative paths that contain the js and CSS files.

For example, I noticed this wrong relative inside index.html <script type=module src=/js/app.4dcb0a0b.js></script> The correct one should be <script type=module src=./js/app.4dcb0a0b.js></script> It should be ./js and not /js.

After I corrected the relative paths, index.html appear correctly.

It is tedious if I have to manually change the wrong relative paths every time. How can I have a better solution?

I am using @vue/cli 5.0.1, yarn v1.22.17



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source