为什么 `node_modules` 想法存在?
why `node_modules` idea exists?
node_modules
文件夹背后的原因是什么?为什么不直接使用 $CWD/mymodule
而不是 $CWD/node_modules/mymodule
。对我来说,这似乎是不必要的烦人的老练,但真正的原因是什么?
还有一个附带问题,我可以告诉 npm 忘记 node_modules
并只使用 '.'
代替(git 方式)吗?
我参与过的大多数大型项目都有 10-20 个依赖项。将它们全部放在根级别没有多大意义,编写可以检查过时模块、重建模块、升级它们等的软件变得更加困难。node_modules
作为一种标准化的方式存在,总有某个地方存储第 3 方模块,而不会与您的任何文件夹发生冲突。 require
默认情况下也会查看您的 node_modules
目录,无需您指定模块的直接路径。
此外,正如三十二上校提到的,您不想将其签入您的 git 存储库。
至于你的附带问题,here is the documentation on npm folders. It doesn't look like you can install it in the root of your project, but you can specify the path to the node_modules
directory with the --prefix
flag seen in this answer。
希望对您有所帮助。
node_modules
文件夹背后的原因是什么?为什么不直接使用 $CWD/mymodule
而不是 $CWD/node_modules/mymodule
。对我来说,这似乎是不必要的烦人的老练,但真正的原因是什么?
还有一个附带问题,我可以告诉 npm 忘记 node_modules
并只使用 '.'
代替(git 方式)吗?
我参与过的大多数大型项目都有 10-20 个依赖项。将它们全部放在根级别没有多大意义,编写可以检查过时模块、重建模块、升级它们等的软件变得更加困难。node_modules
作为一种标准化的方式存在,总有某个地方存储第 3 方模块,而不会与您的任何文件夹发生冲突。 require
默认情况下也会查看您的 node_modules
目录,无需您指定模块的直接路径。
此外,正如三十二上校提到的,您不想将其签入您的 git 存储库。
至于你的附带问题,here is the documentation on npm folders. It doesn't look like you can install it in the root of your project, but you can specify the path to the node_modules
directory with the --prefix
flag seen in this answer。
希望对您有所帮助。