Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple package.json files in one package

I have a site running on php that uses Node for a few development tasks. Currently, our team relies on puppet to install the node modules that we use for these development tasks, however, I was thinking of moving to using a package.json file in the root of the site instead.

My problem is this:

My php app is actually 3 separate sites that we have mixed into one (1 public facing site, 1 internal site, 1 client facing site) and its a likely scenario that some installations of the app depend on different node packages (or different versions of the same pacakge). While I know it would be nice to split these apps apart and have each one manage its own dependencies, short of this, is there some way to have multiple package.json files in one site?

In other words:

/package.json /site1/package.json /site2/package.json /site3/package.json 

Or perhaps, is there a way to have the one package.json handle dependencies for more than one app?

I don't know if this makes sense, let me know if I'm just way out in left field here. Thanks!

like image 365
GxXc Avatar asked Jan 09 '13 21:01

GxXc


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?

json file, but there is nothing inherently wrong with multiple package. json files within a repo. Some companies do use mono-repos, for which it would make total sense to have multiple package. json files.

How do I save all dependencies to package json?

To add dependencies and devDependencies to a package. json file from the command line, you can install them in the root directory of your package using the --save-prod flag for dependencies (the default behavior of npm install ) or the --save-dev flag for devDependencies.


1 Answers

As far as I have seen, package.json deals with a single directory's dependencies (and a single instance of node_modules).

Your best bet is to split your applications into separate directories.

Barring that, you could just add all of the dependencies to a single package.json file. It will install into the node_modules folder and any app within that directory will have access to all of the installed modules.

like image 64
hunterloftis Avatar answered Oct 11 '22 05:10

hunterloftis