In my package.json file I have
"homepage" : "http://myname.project.com/myapp",
I build the app using npm run build
and the output confirms that a /build directory was created. Output:
102.97 KB build/static/js/main.bfa46b52.js
24.37 KB build/static/css/main.cfe8a47e.css
The project was built assuming it is hosted at /myapp/. You can control this with the homepage field in your package.json.
The build folder is ready to be deployed.
If I start the app using npm start
or serve -s build
the app will start and the index.html page will load, but the references to static resources from index.html are broken (/myapp/static/js/main.js and /myapp/static/css/main.css). I can navigate directly to to them without the /myapp (localhost:5000/static/js/main.js works; localhost:5000/myapp/static/js/main.js does not work)
If I deploy the build folder to a different plain old apache server under a /myapp directory it seems to work as expected. Is there any way I can configure serve -s build
to serve up pages from a /myapp directory?
The app is currently one page with no links and no implementation of react-router or anything equivalent. The team had been using webpack, but removed it. The app gets bundled using react-scripts.
json or the PUBLIC_URL environment variable that must be set before building the project. When running the react-scripts build script, the %PUBLIC_URL% placeholders inside the index. html file are replaced with the environment variable string.
Option 1: import the image into the component Put the image file somewhere under the src folder. This alone will not automatically make it available, so you have to import the image into the React component where you're using it. import companyLogo from './path/to/logo.
It wasn't clear to me that two things were happening.
npm start
or serve -s build/
still deployed my application from the root directory of the built in static server.The homepage attribute doesn't have anything to do with where your app actually gets deployed. To address this issue I used a postbuild script move the contents of my /build folder to /build/myapp folder. Then it works as expected.
So more discussion about this here: https://github.com/facebookincubator/create-react-app/issues/1354#issuecomment-311506599
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With