doubleyong
管理员
管理员
  • 最后登录2025-12-02
  • 发帖数1198
  • 最爱沙发
  • 喜欢达人
  • 原创写手
  • 社区居民
  • 忠实会员
阅读:8904回复:0

[react]react 使用npm run build后生成的index.html页面打开为空白页

楼主#
更多 发布于:2018-07-09 11:34


问题:react 使用npm run build后生成的index.html页面打开为空白页


原因:在执行npm run build时,要对生成的资源进行相应的路径配置,因为路径配置错误,所以打开显示只是一片空白。
解决:
      1. 找到对应的配置文件,react与vue不一样,配置文件没有显示出来,配置文件是以模块的形式进行使用的,react 中的配置文件路径 : node_modules\react-scripts\config\paths.js中
   大概45行的代码:
 url.parse(publicUrl).pathname : '/' 改为 url.parse(publicUrl).pathname : './'
如下:
function getServedPath(appPackageJson) {
  const publicUrl = getPublicUrl(appPackageJson);
  const servedUrl =
    envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : './');
  return ensureSlash(servedUrl, true);
}
改好后,在运行npm run build,然后,在打开index.html,显示就有内容了.问题解决了
知识需要管理,知识需要分享
游客


返回顶部

公众号

公众号