创建react应用并使用相对目录进行构建 [英] Create react app, build with relative directories
本文介绍了创建react应用并使用相对目录进行构建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的CRA中,当我执行 npm run build时,它会创建一个捆绑文件index.html,该文件的链接如下所示:
In my CRA when I do an "npm run build" it creates a bundle file index.html that has links that look like:
link href="/static/css/main.ef6ca77b.css"
但是我不想让它引用绝对目录。我希望它使用相对目录,例如:
But I don't want it to refer to absolute directories. I'd like for it to use relative directories like:
link href="static/css/main.ef6ca77b.css"
(因此不带初始斜线...)
(so without that initial slash...)
这可能吗?我问的原因是我正在将多个应用程序部署到目录中,并且它们需要相对而非绝对地引用其资源...
Is this possible? The reason I'm asking is I'm deploying multiple apps to a directory and they need refer to their resources relatively and not absolutely...
推荐答案
必须添加:
"homepage": "./"
到package.json
to package.json
这篇关于创建react应用并使用相对目录进行构建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文