单个node_modules文件夹用于多个项目 [英] single node_modules folder for multiple projects

查看:724
本文介绍了单个node_modules文件夹用于多个项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的网站列表:

  project1 / site 
project2 / site
project4 / site
...
projectN / site

每个 site 文件夹包含 node_modules 文件夹, gruntfile.js 文件和 package.json 文件。所以他们看起来像这样:

  project1 / site / gruntfile.js 
project1 / site / package.json
project1 / site / node_modules /
...
projectN / site / gruntfile.js
projectN / site / package.json
projectN / site / node_modules /

一切工作都正常,我的任务,插件和东西。



我想知道是否可以用解决这个问题 node_modules 文件夹,因为我的网站正在使用类似的任务。

  project1 / site / 
project2 / site /
...
projectN / site /
/ node_modules /

这甚至可能吗?我需要做什么?

解决方案

您可以使用 -g 标志与 npm 全局安装模块,如下所示:
npm install -g< modulename>
这将安装所有的模块,以便它们可以被所有的节点项目访问。



然后,您可以创建每个项目所需的链接模块使用 npm link ,如link @jakerella 提及


...有有些情况下,你想要做到这一点。 Coffee-script和
都是具有命令行
接口的应用程序以及库的好例子。在这些情况下,您可以执行以下
之一:


  1. 全局安装,然后npm链接coffee-script或npm链接
    express(如果您在支持符号链接的平台上)。然后
    ,您只需更新全局副本即可将所有符号链接更新为


请参阅 npm文档


I have a list of websites like this:

project1/site
project2/site
project4/site
...
projectN/site

Each site folder has inside node_modules folder, gruntfile.js file and a package.json file. So they look like this:

project1/site/gruntfile.js
project1/site/package.json
project1/site/node_modules/
...
projectN/site/gruntfile.js
projectN/site/package.json
projectN/site/node_modules/

Everything is working fine with my tasks, plugins and stuff.

I am wondering if I can work this out with just one node_modules folder on my root folder as my websites are using similar tasks.

project1/site/
project2/site/
...
projectN/site/
/node_modules/

Is this even possible? What do I need to do?

解决方案

You can use the -g flag with npm to install modules globally, as in: npm install -g <modulename> This will install all the modules so they are accessible to all your node projects.

And then you can create a link for each of the projects to the required modules using npm link, as explained in the link @jakerella referred to:

...there are some cases where you want to do both. Coffee-script and Express both are good examples of apps that have a command line interface, as well as a library. In those cases, you can do one of the following:

  1. Install it globally, and then npm link coffee-script or npm link express (if you’re on a platform that supports symbolic links.) Then you only need to update the global copy to update all the symlinks as well.

See the npm documentation.

这篇关于单个node_modules文件夹用于多个项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆