When I build my CRA app I get a path for my assets (css, images) that begins with
/static. If I deploy my app to
https://something.com/myapp, then the app will try to access those asset paths at
https://something.com/static/asset.css. That’s not where the asset lives. The asset lives at
Create React App allows you to change the prefix for a the built assets with the
homepage attribute in your package.json file.
You could set it to myapp:
And then the asset will have the path of
/myapp/static/asset.css, but what if you want to change paths?
. will make the asset always relative to
index.html, allowing you to not be concerned with the path the application is deployed to.
This actually repurposes a property of the package json file that npm uses to set the homepage of an npm package, so you may find this property used in a different way in other package.json files.
See the npm docs here.
See the Create React App docs hereTweet