简体   繁体   中英

Implement Server Side Rendering in existing Backend React

I have a project with a project structure like this:

Project root
-client
 -package.json
 -src  //folder containing react components
  -....
 -build
  -...
-package.json
-app.js //server

From what I have been able to understand, SSR requires a single package.json for both server and client. This doesn't seem too scalable to me. Is there any way to do this without combining the package.json files?

Backend's package.json must contain all packages that are involved in React rendering on the front end side as it will do the same thing at the backend. But the front end does not need to have all the packages that are used in the backend.

It is possible to do it manually. In the past, I have had a project structure where I did merge front-end packages with backend projects for SSR support. In my experience, it is a bit too much work without any real value. I recommend porting to some framework like Nextjs which makes this possible and cuts a lot of boilerplate code off.

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