Using npm workspaces I have a folder structure like this
+-- package.json
+-- package-lock.json
+-- client
| `-- package.json
+-- shared
| `-- package.json
`-- server
`-- package.json
Normally when creating a production build for a nodejs app I would run npm ci --only=production
and then copy node_modules
into a build artifact. I'm not sure how to do something like that when working with workspaces.
If I run npm ci --only=production --workspace server
it splits the dependencies across ./node_modules
and ./server/node_modules
. Maybe I should copy (merge?) both node_modules
into a build artifact?
Another option could be to copy ./package-lock.json
and ./server/package.json
into a fresh directory and run npm ci --only=production
. It does seem to work but I don't know enough about npm to know if this is a good idea.
The requirements are:
node_modules
should only include production dependencies for the chosen package- The dependency versions should be determined by
package-lock.json
.
npm ci --only=production --workspace server
but it does mean the artifact has an extra directory level which is a bit annoying. I was having a few issues with npm workspaces like this github.com/npm/cli/issues/3847 so ending up dropping them for now. – Isis