I've written a small react app to test the build
command.
Simply I didn't change anything after running npx create-react-app .
I've only deleted everything inside ./src
folder as usual, and created ./index.html
and ./components/App.js
and after that I ran the npm run build
command, and here is the files tree:
.
├── build
│ ├── static
│ │ └── js
│ │ ├── 2.cc830c28.chunk.js
│ │ ├── 2.cc830c28.chunk.js.LICENSE.txt
│ │ ├── 2.cc830c28.chunk.js.map
│ │ ├── main.c49fc855.chunk.js
│ │ ├── main.c49fc855.chunk.js.map
│ │ ├── runtime-main.900dd88b.js
│ │ └── runtime-main.900dd88b.js.map
│ ├── asset-manifest.json
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
├── public
│ ├── favicon.ico
│ ├── index.html
│ ├── logo192.png
│ ├── logo512.png
│ ├── manifest.json
│ └── robots.txt
├── src
│ ├── components
│ │ └── App.js
│ └── index.js
├── package.json
├── package-lock.json
└── README.md
Now, what I've done is to go to ./build/index.html
file, and trying to open it inside the browser, --> nothing? blank page? why?
- but if you normally run npm start and navigate to
localhost:3000
in the browser, you'll see everything working. - and if you
npm i -g serve
from inside./
directory and then ranserve ./build
and then navigate tolocalhost:5000
you'll see your./build/index.html
file working and everything shows up normally.
so what is the magic with serve
, why I need to serve the file in order to render the content on the screen? why I can't just open ./build/index.html
file?
just for the curios folks,
./src/index.js:
import React from 'react'
import ReactDOM from 'react-dom'
import App from './components/App'
ReactDOM.render(<App />, document.querySelector('#root'))
./src/components/App.js
import React from 'react'
export default function App() {
return (
<div>
Hello From React App
</div>
)
}
Some people suggested to add the "homepage" property inside the ./package.json
file, but I need instructions on where to put it and how?