built files are meant to be served over an HTTP server. Opening index.html over file:// won't work

npm run build之后,出现提示:Tip: built files are meant to be served over an HTTP server. Opening index.html over file:// won‘t work.

打开dist文件夹里的index.html文件,页面无法显示,控制台报错如下:
built files are meant to be served over an HTTP server. Opening index.html over file:// won't work_第1张图片

解决1:将绝对路径改为相对路径

**修改目标文件:**项目目录 > config文件夹 > index.js

assetsPublicPath:'/' 改为:assetsPublicPath:'./' 

built files are meant to be served over an HTTP server. Opening index.html over file:// won't work_第2张图片
需要注意的是,不是修改dev下的assetsPublicPath,而是修改build下的assetsPublicPath

重新打包之后,运行dist里的index.html,页面能够显示了,但是背景图片却无法显示,控制台报错如下:

built files are meant to be served over an HTTP server. Opening index.html over file:// won't work_第3张图片

解决2:配置背景图片路径

修改目标文件:项目目录 > build文件夹 >utils.js

publicPath:'../../',

built files are meant to be served over an HTTP server. Opening index.html over file:// won't work_第4张图片

再次npm run build,dist文件里的index.html即可正常运行

你可能感兴趣的:(项目问题集合)