我们需要在 bitbucket 上推送 node_modules 吗

Do we need to push node_modules on bitbucket

在 bitbucket 上推送 angular2 应用程序时,我们是否还需要推送 node_modules 和 typings 文件夹?我必须在 azure 上部署该应用程序。据我从各种文章中了解到,当我们在 Azure 上部署时,它会运行 npm install 本身,因此会创建 node_modules 和 typings 文件夹。请分享这个。

不,不需要推送 node_modulestypings 文件夹。 npm install 会将您的依赖项安装到这些文件夹中。

您不必将 node_modules 文件夹与您的项目一起推送。如果你在 package.json 的依赖项中声明了它,那么克隆你的项目并运行 npm install 的人将下载正确的东西。声明 package.json 的一种简单方法是在安装时使用 --save

例如。 npm install bootstrap --save

根据 Azure's documentation

Azure Cloud Services expect all modules to be installed on the development environment, and the node_modules directory to be included as part of the deployment package. It is possible to enable support for installing modules using package.json or npm-shrinkwrap.json files on Cloud Services, however this requires customization of the default scripts used by Cloud Service projects. For an example of how to accomplish this, see Azure Startup task to run npm install to avoid deploying node modules

他们也在这个问题上展开:

When deploying the node_modules directory as part of your application, it will increase the size of the deployment compared to using a package.json or npm-shrinkwrap.json file; however, it does guarantee that the version of the modules used in production are the same as those used in development.

在代码管理方面,there are conflicting positions whether the node_modules folder should or shouldn't be submitted to version control. What I can say is that after the left-pad incident越来越多的人开始朝着"should commit"方向发展,包括我自己

如果你想走这条路,我建议你看一下 shrinkwrap, which locks the versions of the packages your dependencies themselves depend on, and shrinkpack 这两个将实际包保存为 .tar 以避免嘈杂的提交更改。

最佳做法 - 不要将 node_modules 推送到 git 存储库。

为了避免依赖性问题 - 使用像 shrinkwrap 这样的模块(它锁定了包依赖性的版本)