私はしようとしています
PUBLIC_URL=http://example.com npm run build
最新の create-react-script を使用して構築されたプロジェクトを使用します。
%PUBLIC_URL%
ただし、の出現は、public/index.html
期待される値ではなく、空の文字列に置き換えられますPUBLIC_URL
。
public/index.html
次のようなコードが含まれています
<script src="%PUBLIC_URL%/static/js/jarvis.widget.min.js"></script>
インターネットと Stack Overflow を何時間も検索した結果、 について書かれたものはほとんどないことがわかりましたPUBLIC_URL
。 GitHub から create-react-app をクローンし、コードを閲覧していますが、まだわかりません。
私が何を間違っているのか、何かアドバイスはありますか?
ベストアンサー1
他の回答が役に立たない場合は、 にもフィールドがありますhomepage
。package.json
実行すると、npm run build
次のようなメッセージが表示されます。
The project was built assuming it is hosted at the server root.
To override this, specify the homepage in your package.json.
For example, add this to build it for GitHub Pages:
"homepage" : "http://myname.github.io/myapp",
ルートフィールドの1つとして追加するだけですpackage.json
。例:
{
// ...
"scripts": {
// ...
},
"homepage": "https://example.com"
}
homepage
または経由で正常に設定された場合PUBLIC_URL
、代わりに次のようなメッセージが表示されます。
The project was built assuming it is hosted at https://example.com.
You can control this with the homepage field in your package.json.