![](/img/trans.png)
[英]Problem with relative path when deploying react app to a subfolder in GitHub pages
[英]nwb build-react-app creates root path rather than relative path
我正在測試nwb,以使用此示例項目簡化構建React應用程序。 構建應用程序時,index.html中引用的css和js文件的路徑位於根目錄,而不是相對目錄。 有什么辦法可以更改引用?
例如:
在html中,參考如下:
<script type="text/javascript" src="/vendor.b3f34f12.js"></script>
<script type="text/javascript" src="/app.9b5c57d3.js"></script>
代替,
<script type="text/javascript" src="./vendor.b3f34f12.js"></script>
<script type="text/javascript" src="./app.9b5c57d3.js"></script>
您可以在nwb.config.js
文件中使用webpack.publicPath
為此:
如果要創建與路徑無關的構建,請將
publicPath
設置為空白:module.exports = { webpack: { publicPath: '' } }
來源: https : //github.com/insin/nwb/blob/master/docs/Configuration.md#publicpath-string
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.