简体   繁体   中英

How to add package.json file to built react app?

If use npm build command to build a react app for production environment, we can get a build named folder. There are html, css and JavaScript in it, but the package.json file doesn't exists.

If we use this file to set http proxy endpoint to connect API, we can't run the app well because the endpoint can't be found.

How to deal with this json file rightly in this case?

First if you have package.json of some Node-React application you can run in example windows CMD (terminal console) and make some folder there you put this package.json and navigate to this folder and then, there typing npm install. On this away you can prepare all what is need for this Node-React app. Exactly with this command starting make node_modules folder there stat install need package. Next step is make folders: src and public, there you put next file : on Src folder App.js, index.js, App.css on public folder index.html. That is because in this package.json exists all what is need for starting application, but if you menually build package.json this can make with run npm. init in CMD.
Use Proxy in package.json file you can use for example if you send some data in case client-server app. There you have in client for HTTP request axios, on server side express. In package.json file add row "proxy":" http://localhost:3001 " from server. For that plz. look How to set port for express server dynamically?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM