简体   繁体   English

我可以通过package.json将依赖项加载到node_modules以外的单独文件夹中吗

[英]can I load dependencies in a separate folder other than node_modules via package.json

When I run this I am downloading all the dependencies in the node_modules directory 运行此命令时,我正在下载node_modules目录中的所有依赖项

{
  "name": "bootstrap-test-app",
  "engine": "node 5.5.0",
  "engineStrict": false,
  "version": "1.0.0",
  "description": "",
  "main": "master.js",
  "scripts": {},
  "author": "soum",
  "license": "BSD-2-Clause",
  "devDependencies": {},
  "dependencies": {
    "bootstrap-sass": "latest",
    "jquery": "3.1.1",
    "requirejs": "2.1.22"
  }
}

My question is it possible to set a path for the dependencies instead of node_modules for example lets say in a dorectory called "dependencies"? 我的问题是可以为依赖项设置路径,而不是为node_modules设置路径吗?例如,让我们在称为“依赖项”的目录中说吗? Can I set a destination property relative to the root of project so that my file structure looks like this 我可以相对于项目的根设置目标属性,以便我的文件结构如下所示吗

my-app
  package.json
  dependencies
    -bootstrap-sass
    -jquery
    -requirejs
  node_modules

No, it is not possible now and it is very unlikely to be possible in the future. 不,现在不可能了,将来也不太可能。

See this issue on GitHub from 2013 and the comments there: 从2013年开始在GitHub上查看此问题,并在此处发表评论:

The future of that can be summarize by two quotes from that discussion: 该讨论的未来可以通过该讨论中的两句话来总结:

  1. "Is there any way to change the location where the node_modules folder gets installed for local installed dependencies...??" “是否有任何方法可以更改本地安装依赖项的node_modules文件夹的安装位置??”
  2. "no, there is not, and there are no plans to implement such a feature." “不,没有,也没有实现这种功能的计划。”

See also an older issue from 2011: 另请参阅2011年以来的旧问题:

What you can do is to create a directory that you want and a symlink called node_modules with something like that: 您可以做的是创建一个所需的目录以及一个名为node_modules的符号链接,其内容如下:

$ mkdir dependencies
$ ln -sv dependencies node_modules
‘node_modules’ -> ‘dependencies’
$ npm i tryjson -S
customdeps@1.0.0 /home/rsp/node/test/customdeps
└── tryjson@1.1.4 
$ ls dependencies
tryjson

I just came up with that idea. 我只是想出了这个主意。 I wasn't sure if npm can install in a symlinked directory but I just tested it and it turns out that it can. 我不确定npm是否可以安装在符号链接目录中,但我刚刚对其进行了测试,事实证明它可以。

Of course to actually use those dependencies in Node, you'd have to set the NODE_PATH environment variable accordingly. 当然,要在Node中实际使用这些依赖项,您必须相应地设置NODE_PATH环境变量。 See: 看到:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从Package.json和Node_modules文件夹中删除依赖项 - Remove dependencies from Package.json and Node_modules folder 如何立即将node_modules中的所有依赖项添加到package.json? - How can I add all dependencies from node_modules to package.json at once? 如何从node_modules文件夹添加您的package.json依赖项? - How to add your package.json dependencies from node_modules folder? 如何将 package.json 与 node_modules 分开 - How to separate package.json from node_modules 从现有的 Node_Modules 文件夹构建 Package.Json? - Build Package.Json From Existing Node_Modules Folder? 如何清除不在 package.json 中的包的 node_modules 文件夹? - How to clean node_modules folder of packages that are not in package.json? 用于全局node_modules的package.json - package.json for global node_modules 即使我的 package.json 和 node_modules 文件夹中有它们,我也得到了未定义的包 - I'm getting undefined packages even though I have them in my package.json and node_modules folder npm 卸载会从 package.json 中删除 package,但不会从 node_modules 文件夹中删除它 - npm uninstall removes the package from package.json but doesn't remove it from node_modules folder 更新package.json文件,并将其依赖项手动复制到node_modules中 - Update package.json files with dependencies manually copied over into node_modules
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM