React项目build之后资源文件路径为根目录问题解决
2017-12-28 本文已影响3765人
一叶信笺飘云间
找到node_modules -> react-scripts -> config -> paths.js
修改
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl =
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');//改成'./'
return ensureSlash(servedUrl, true);
}
为
function getServedPath(appPackageJson) {
const publicUrl = getPublicUrl(appPackageJson);
const servedUrl =
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : './');
return ensureSlash(servedUrl, true);
}
再重新编译打包即可