Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How upload reactjs project to ftp?

Tags:

reactjs

I'm newbie on react, I did 2 paged website for exercise, all is working well on my localhost.

But i'm confused about how upload project to my linux server.

What i did ? I create react app via terminal with this command :

create-react-app react-demo-project

Terminal create my project and in project root i have node_modules directory.

so here is i have some questions:

1- React project will work normally on linux hosting?

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

like image 383
user3348410 Avatar asked Oct 01 '17 08:10

user3348410


People also ask

Where do I upload React JS project on server?

For your React app, you'll have to drag and drop the build folder onto the Netlify Dashboard. Run npm run build beforehand to deploy the latest build. You can also connect GitHub, GitLab, or Bitbucket, depending on where your project is stored.

How do I upload to server React?

Configure the deploy settings. Select a default branch to deploy (you can choose the master branch or any other branch) and ensure that the build command is npm run build and the publish directory is /build . Click Deploy site, and your React app will be deployed on Netlify's remote server.


2 Answers

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 !

like image 105
Mohammad Avatar answered Sep 20 '22 11:09

Mohammad


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

like image 31
kiranvj Avatar answered Sep 22 '22 11:09

kiranvj