score:0

add this line to package.json:

"homepage": "./"

that should make it work without the need to adjust index.html after every build.

enter image description here

score:4

1- react project will work normally on linux hosting?

yes, it will work in all webservers, unless you have server side rendering (ssr)

2- i need to all my project upload to ftp? because there is arround 20.000 file in node_modules directory.

files in node_modules will not go to your web server. these are development dependency files used only during development.

  1. run npm run build
  2. this will create a folder called build in project root. this will have all html, css , images and js files
  3. copy all files and folders in build folder to your site root.

if your site has to be hosted in a sub folder in root you need to do the below, otherwise you will see a blank page. this is because your static files (css, js etc) are not loaded correctly.

open package.json add a new entry homepage: /your_subfolder/

it will look like this

homepage in package.json

now do steps mentioned above and your site should work fine

score:8

create-react-app has a command to bundle your app to a ready to deploy state.

npm run build

this command will bundle your app in /build folder. with the contents of this folder you can deploy your app in any hosting environment. you don't need to install your packages and libraries manually when you use this command. more information about using this command and deploying your app in different hosting environments can be found create-react-app readme

deployment

npm run build creates a build directory with a production build of your app. set up your favorite http server so that a visitor to your site is served index.html, and requests to static paths like /static/js/main.<hash>.js are served with the contents of the /static/js/main.<hash>.js file.

score:30

with this command build your app :

npm run build

build folder has created in your project directory, open index.html in your browser and check output...

if you saw a blank page (after build and opening index.html) , you must change the main js file path in the index.html :

default is : src="/static/js/main.ddfa624a.js" change to : src="./static/js/main.ddfa624a.js"

i changed js path and this worked !


Related Query

More Query from same tag