Vue项目打包后提示Opening index.html over file:// won't work.

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38543537/article/details/90755965

最近使用npm run build 打包Vue项目是出现报错如下:

百度翻译:

提示:构建的文件应该通过HTTP服务器提供服务。

在文件:/上打开index.html不起作用。

它提示提示:建立文件是放在一个HTTP服务器。打开index.html文件:/ /不工作。当直接使用浏览器打开文件时,浏览器控制台会报错

因为vue-cli的默认配置中, publishPath是用绝对目录

于是寻找解决办法,如下:

改config\index.js中的build的对象
assetsPublicPath: '/',

改为
assetsPublicPath: './',
即可

当然也可以在dist,执行以下命令:

cd dist
npm install -g http-server
hs

猜你喜欢

转载自blog.csdn.net/qq_38543537/article/details/90755965
今日推荐