记录关于webpack 首次打包后,访问打包好的index.html页面白屏问题

155 阅读1分钟

第一次用webpack打包时,发现打包后的index.html 文件访问后,页面白屏。其实是由于webpack在打包过程中对于一些资源文件使用了绝对路径,index.html 文件中无法根据绝对路径找到相应的资源文件。 解决方案

修改webpack打包文件中的配置:

1.在webpack.prod.conf.js中增加publicPath:’./’ ;
2.util.js中增加publicPath:’./’
3.config/index.js修改assetsPublicPath:‘./’;

具体请看图片:

20200401231949523.png

20200401232028199.png

20200401232059332.png