我可以通过复制node_modules来移动依赖库吗?

原创
2017/05/26 23:00
阅读数 7.7K

简单的讲,是可以的。但是每个人电脑环境的不同,node_module安装的顺序也不同,可能会出问题不同的问题,虽然说依赖树的结构并不影响您的工程,但为安全起见,如果遇到问题时,请直接在工程目录下面npm install,假设工程下有package.json文件。那么你将得到跟来源机器完全一样的依赖库。

npm v3 dependency installation is now non-deterministic meaning you may get different packages depending on the order in which packages have been installed over time. This isn't necessarily a bad thing, just something to be aware of.

npmv3依赖安装是不确定的了,意思是你将在不同的运行环境安装不同顺序的依赖包,一般不是件坏事,但要知道。

Given this change I personally don't copy my node_modules directory around too much (it's still possible though!) and instead opt for a clean install most of the time.

根据这个变化我个人是不经常复制node_modules(虽然仍有可能!)而是保留/opt/目录一个干净的安装版本。

There are new tools like Yarn Package Manager which can speed up the installation process if you are doing that a lot (but as of 2017-05-12 it's unclear how well it handles private npm organisations and private scoped packages).

这里介绍一个加速安装过程的包管理器Yarn Package Manager,如果你需要经常移动依赖包的话(但目前为止不确定对私有包管理的好不好)

So the takeaway is still pretty much the same: it won't hurt, but maybe err on the side of a clean install. If something weird does happen and you run into problems then you can just delete node_modules and run npm install.

所以结论仍是:无害,但可能出错,如果见鬼了,你可以直接干掉node_modules然后npm install

Thanks to https://stackoverflow.com/questions/24102022/is-it-safe-to-copy-node-modules

展开阅读全文
加载中

作者的其它热门文章

打赏
0
0 收藏
分享
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部