简体   繁体   English

尽管已经使用npm安装了,但我是否需要在lib或vendor文件夹中保留js库的副本?

[英]Do I need to keep a copy of js library in lib or vendor folder though already installed using npm?

Question 1 : I am installing my project dependency libraries using npm and it gets stored in the npm_modules folder. 问题1:我正在使用npm安装我的项目依赖库,并且将其存储在npm_modules文件夹中。 Is it necessary to keep the copy of library like angular.js , angular-route.js in lib folder or vendor folder? 是否有必要在lib文件夹或vendor文件夹中保留angular.jsangular-route.js类的库副本? I could see few people are using lib folder or vendor folders to store the library in the permanent manner. 我可以看到很少有人使用lib文件夹或供应商文件夹以永久方式存储库。 I am confused by seeing this. 看到这个我很困惑。

Question 2: Do I need to copy/paste the node_modules folder to production or just run the npm install command on the project folder's command prompt to install all the dependencies in production. 问题2:我是否需要将node_modules文件夹复制/粘贴到生产环境中,或者仅在项目文件夹的命令提示符下运行npm install命令以将所有依赖项安装在生产环境中。 How does a dependency library get promoted to production? 依赖库如何提升为生产环境?

Thank you kindly for your advice. 谢谢您的建议。

It all depends on how you need to deploy your site to production, really. 实际上,这完全取决于您需要如何将站点部署到生产环境。 Ultimately, you will probably want to bundle all your JS files into one or a few files, which are minified and sent with gzip compression. 最终,你可能会想,以你的所有的JS文件打包成一个或几个文件,这些文件微细化以及用gzip压缩发送。

How you bundle them is up to you. 如何捆绑它们取决于您。 There are quite a few options: 有很多选择:

  • Browserify Browserify
  • Webpack 的WebPack
  • Grunt / gulp build process 咕unt声
  • And many more besides 还有更多

As to whether you need to keep a copy of these bundled javascript files under version control, well I think that boils down to 1 key question: can you run a build process (such as one of the tools using NodeJS) on the production server, or on a build server that creates a zip file or installer? 关于是否需要在版本控制下保留这些捆绑的javascript文件的副本,我认为可以归结为一个关键问题:您可以在生产服务器上运行构建过程(例如使用NodeJS的一种工具),还是在创建zip文件或安装程序的构建服务器上? If so, then you don't need to include them, just get the build server or production server to check out the latest copy from version control, npm install and then run the build process. 如果是这样,则您不需要包括它们,只需获取构建服务器或生产服务器即可从版本控制, npm install检出最新副本,然后运行构建过程。

But if the best you could do is have the production server check files out from source control, then you would want to include the final versions of the files to use in the repository. 但是,如果您能做的最好是让生产服务器从源代码管理中检出文件,那么您将希望包括要在存储库中使用的文件的最终版本。

Keeping generated files , such as your bundled javascript files, in your source control repo should be avoided where possible. 应尽可能避免将生成的文件 (例如捆绑的javascript文件)保留在源代码控制存储库中。 Because otherwise, every commit has to contain the changes to the source files, and the corresponding change to the generated files as well. 因为否则,每个提交都必须包含对源文件的更改以及对生成文件的相应更改。 And the latter is just noise, and has to be ignored by every developer looking at a diff/patch for a commit. 后者只是噪音,每位查看差异/补丁进行提交的开发人员都必须忽略后者。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM