Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notating Multiple Modules in the Same Package.json File

I am trying to package up some modules that I have been working on. I have five modules, split in to five files. Four of them are the actual outward-facing modules that I want the user to be able to install. The other one is a support module that they all need to function correctly. They are all stored in the same directory. I want to be able to specify each as a separate module in the same directory. But as far as I can tell, one can only define a single module in package.json.

Is there a way to specify multiple modules? If not, that means this must be a bad practice. How should I structure my module's exports to move it in to one main module?

like image 391
Wasabi Fan Avatar asked Jun 29 '14 18:06

Wasabi Fan


People also ask

Can we have 2 package json?

If you use the two-package. json project structure, you'll only have your devDependencies in your development package. json and your dependencies in your app package.

Can you have more than one package json file?

In terms of keeping things simple, it is easier to only have to maintain a single package. json file, but there is nothing inherently wrong with multiple package. json files within a repo.

Can I modify package json file?

you can just open it with nano and edit it manually...


1 Answers

Currently there's not a supported way of having a separate package.json file for each module you'll be publishing within the same directory. And really, this makes sense, as each package you deploy may have issues, feature requests, bugs, etc that need to be handled separately and don't force updates of the others. Separating these out will allow you to focus on the maintenance of each independently, and also allow the consumers of these modules to include them separately. A lot of larger scale projects who have started by creating something they think people will like, end up having the thing that everyone actually use be the random sub-project that was created separately.

So separate directories, and separate package.json files, then include dependencies within the package.json for each. If you haven't already seen there's a couple good writeups to help development of node packages here:

  • https://docs.npmjs.com/about-packages-and-modules
  • https://docs.npmjs.com/creating-a-package-json-file
  • https://docs.npmjs.com/using-npm-packages-in-your-projects
like image 128
dylants Avatar answered Dec 02 '22 09:12

dylants