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 fromA/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 runsnpm run build
in folder B? I guess it has much to do with the npm run-script usage.
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 fromA/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 runsnpm run build
in folder B? I guess it has much to do with the npm run-script usage.
3 Answers
Reset to default 14This 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.
- copy is not a problem, just make it be automatic. Introduce a deployment step is not bad.
- there will not be any
cross origin
problem because you are servingfront-end
as static files. or at least thecross origin
problem should do no matter with it - people first. split or not split projects, depends on developers
front-end
package also a service, or just static files? – Jiang YD Commented Jun 6, 2017 at 9:16