The question is pretty straightforward: Is there some way to publish two different NPM modules to the npmjs registry from a single nodejs project?
But for those of you wondering why the heck would someone even want to do that? ... the motivation behind this question may not be too obvious. So allow me to explain:
I use something akin to an app-server called loopback. And my nodejs app is neatly distributed into client, common and server folders.
I often need to reuse the models in my
common
folder across other projects as well. And although I can publish just that folder as a separate NPM module by using.npmignore
to remove the other stuff:/* /common/utils /common/models/*.js !/common/models/*.json
I cannot remove the clutter from my current
package.json
, which is needed to actually run my app, from what has been published.$ npm pack $ tree -L 2 ~/dev/w2/node_modules/warehouse ~/dev/w2/node_modules/warehouse ├── README.md ├── common │ └── models ├── node_modules │ ├── ... │ └── ... └── package.json
As things stand, I filtered out everything other than mycommon/models
folder but since I'm not sure how to dynamically tweak the package.json file before packing it or as part of packing it ... annpm install
will put down the dependencies that really aren't required.I am not thrilled at the alternative of creating a separate project solely with models in it as that forces me to add it as a dependency to the core project and active development gets split across 2 projects where it used to be just one.
npm link
etc is a good approach to get around it but it adds complexity to developer setup when onboarding new folks and making sure that nobody checks in the wrong thing.
So is there some way to publish two different NPM modules to the npmjs registry from a single nodejs project? Or some way to use different package.json file for a separate publication but all from one project?
Update: What is my goal?
To reuse the models from my core project, across other projects, by publishing them as a NPM module. WITHOUT giving up the convenience of continuing to develop my core project as ONE atomic entity without npm link
etc. as that gets messy fast when more than just one person is working on it.
separate it out from the app
... as I point out in bullet 2, I'm asking this question so I don't have to do that, I'm looking to push the envelope here a bit. – Fluidizecommon
and how it interacts with your project.. – Addiedon't try to avoid going over them again – instead state why you've ruled them out
when I wrote:as that forces me to add it as a dependency to the core project and active development gets split across 2 projects where it used to be just one
– Fluidize