Vue CLI build and run index.html file without server
I ran into a similar issue and the following two changes helped me to make it work. Now I can just open index.html in Chrome as a file to run my SPA from file system.
In
vue.config.js
, I did not have apublicPath
configured, which resulted in the default"/"
.
I had to configure it to empty string like this so that it uses relative paths:module.exports = { publicPath: '', }
PS: Since Vue CLI 3.3 use
publicPath
instead of the now deprecatedbaseURL
I was using the
history
mode ofvue-router
, which does not work on a local file system to route the paths back to index.html. So I omitted the mode to go back to the defaulthash
mode.
I was able to fix this issue by manually changing the url
of the referenced files.
It's a bit of a pain, but this was a solution without having to mess around with the build configuration.
What you need to do:
- Open
index.html
- Find
href=/
and replace withhref=
- Find
src=/
and replace withsrc=
NOTE: I was in need of this solution because I was creating a Phonegap app.