I've this directories and I'm trying to deploy my website using firebase hosting
When I do
npm run build
I get this build folder as result
As you can see my javascript files are not included in the build project.
When I run
firebase deploy
it deploys only the index.html with the css files.
What is going on?
I created react app with following command:
npx create-react-app my-app
Then executed the command, to create build:
npm run build
Then uploaded the build folder output to gcp storage.
And when I am trying to access the index.html file via Link URL. In Console I am getting 404 for Css and Js file referenced in index.html
When I updated the index.html with correct url link of js and css, then it is working fine.
Is it necessary to change the js and css link reference to gcp storage url link? Can't that work with relative paths?
Depends on how you uploaded your files to Cloud Storage.
You can do gsutil rsync -R local-dir gs://www.example.com to recursively copy a directory tree to Cloud Storage. Which what the -R option is used for
I had created a React app using npm init and used webpack.
Project is running successfully and able to work integrated with Express JS also.
I had created dist folder using the command npm run build which created bundle.js file along with the index.html file.
When I try to open index.html file in chrome browser nothing gets displayed except header and footer, no error in console.
I expect the login form which is my application's home page to load when i open index.html file chrome browser.
I am trying to deploy this react project https://github.com/tahnik/react-expressjs
and use apache server for static file. The example that I know that is working is on Angular, on angular we just run ng build --prod and this will create a dist folder where there is an index.html. On apache, we just serve the dist folder. But here we use React with webpack that not contain dist folder with an index.html so I don't know how to do that on your project.
PS : Sorry for my english, it's not my native language
Thanks
There is no index.html because it is a server side rendered application. In the repository you posted, the whole project is meant to be running as a server side application, there is no index.html file. Everything is served from express as you can see here.
When you run npm run build:client it just creates the js/css files. You would need to:
Create your own html and add css and js to it.
Add html-webpack-plugin to generate the html with all the css/js files already on it.
If you don't want to do that. You simply run npm start after your npm run build and the server will start. now you need to proxy from apache to this addr:port.
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.
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 !
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.
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.
Run npm run build
This will create a folder called build in project root. This will have all html, css , images and js files
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
Now do steps mentioned above and your site should work fine
Add this line to package.json:
"homepage": "./"
That should make it work without the need to adjust index.html after every build.