I created an express-based backend (in folder A) and a related react-based front-end project (in folder B) respectively. Now I put B inside A for the following benefits:
I don't need to copy files from font-end build to server project anymore because A/server.js can serve files from A/B/build directly.
No need to worry about the cross origin request errors.
They look like one project and are easier to manage in GitHub.
But can I run npm run buildjs from folder A, which actually runs npm run build in folder B? I guess it has much to do with the npm run-script usage.
This can be done using --prefix <path>. From folder A:
npm run --prefix ./B build
You could add the following to A/package.json:
{
...
"scripts": {
"buildjs": "npm run --prefix ./B build"
},
...
}
I noticed that you can also go up using the --prefix. For example:
npm run --prefix ../ build:frontend
Only downside is that you can't pass arguments using the -- <args> syntax.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With