People like me who are looking for something like this in in build:
<script type="text/javascript" src="https://dsomething.cloudfront.net/static/js/main.ec7f8972.js">
Then setting https://dsomething.cloudfront.net
to homepage
in package.json
will not work.
1. Quick Solution
Build your project like this:
(windows)
set PUBLIC_URL=https://dsomething.cloudfront.net&&npm run build
(linux/mac)
PUBLIC_URL=https://dsomething.cloudfront.net npm run build
And you will get
<script type="text/javascript" src="https://dsomething.cloudfront.net/static/js/main.ec7f8972.js">
in your built index.html
2. Permanent & Recommended Solution
Create a file called .env
at your project root(same place where package.json is located).
In this file write this(no quotes around the url):
PUBLIC_URL=https://dsomething.cloudfront.net
Build your project as usual (npm run build
)
This will also generate index.html with:
<script type="text/javascript" src="https://dsomething.cloudfront.net/static/js/main.ec7f8972.js">
3. Weird Solution (Will do not work in latest react-scripts version)
Add this in your package.json
"homepage": "http://://dsomething.cloudfront.net",
Then index.html will be generated with:
<script type="text/javascript" src="//dsomething.cloudfront.net/static/js/main.ec7f8972.js">
Which is basically the same as:
<script type="text/javascript" src="https://dsomething.cloudfront.net/static/js/main.ec7f8972.js">
in my understanding.
Github Issue
Github Comment