|
问题: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,显示就有内容了.问题解决了 |
|
|