git 应该忽略 bower_components 吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22327758/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 17:52:21  来源:igfitidea点击:

Should bower_components be gitignored?

gitgitignorebower

提问by Pierre de LESPINAY

Would it be good practice to keep only the bower.jsonfile and gitignore the whole bower_componentsdirectory?

只保留bower.json文件并 gitignore 整个bower_components目录是一种好习惯吗?

采纳答案by TimWolla

The official Bower pagestated:

Bower官方页面指出:

N.B.If you aren't authoring a package that is intended to be consumed by others (e.g., you're building a web app), you should always check installed packages into source control.

NB如果您编写的包不是供其他人使用的(例如,您正在构建 Web 应用程序),则应始终将已安装的包签入源代码管理

Make sure to check out the link in the quote, it discusses some pro and cons. The main pro it mentions is that checking them in ensures that your dependencies are always available, as long as your repository is available. No matter what happens to Bower, GitHub or whatever else would be needed otherwise.

请务必查看报价中的链接,它讨论了一些优点和缺点。它提到的主要优点是,只要您的存储库可用,检查它们就可以确保您的依赖项始终可用。无论 Bower、GitHub 或其他任何其他需要的东西发生了什么。

回答by user12121234

The .gitignorefile in a newly generated YeomanAngularJS project has bower_components (and node_modules) listed to be ignored (if you don't know Yeoman it is a very reputable web scaffolding tool for modern webapps, so that's good enough for me!):

新生成的YeomanAngularJS 项目中的.gitignore文件列出了要忽略的 bower_components(和 node_modules)(如果你不了解 Yeoman,它是一个非常有信誉的现代 web 应用程序的 web 脚手架工具,所以这对我来说已经足够了!):

.gitignore

.gitignore

node_modules
dist
.tmp
.sass-cache
bower_components

回答by JoshuaDavid

There's a time & a place for both approaches. For Yeoman it's appropriate to rely on bower.json because it's a tool in a toolchain and needs to stay living and breathing with the bower ecosystem. For a deployable web app, it's generally good practice to commit dependencies and maintain more control.

两种方法都有时间和地点。对于 Yeoman 来说,依赖 bower.json 是合适的,因为它是工具链中的一个工具,需要与 bower 生态系统一起生存和呼吸。对于可部署的 Web 应用程序,提交依赖项并保持更多控制通常是一种很好的做法。

Here's an good articleI like that discusses this.

这是一篇我喜欢的好文章,讨论了这个问题。

回答by Yves

If you're using Grunt and Node with Bower it makes sense to put bower_componentsin your .gitignore because when you run grunt serveor grunt buildit takes care of the dependencies for you, I'm sure that's why in Yeoman they add it to the .gitignore

如果您在 Bower 中使用 Grunt 和 Node,那么将bower_components放在您的 .gitignore 中是有意义的,因为当您运行grunt servegrunt build 时,它会为您处理依赖项,我确定这就是为什么在 Yeoman 中他们将其添加到.gitignore

回答by Erich Cervantez

The Yeomangenerator pre-filled the .gitignorefile with bower_components, but it also pre-filled with other directories I would think would be needed for a final app (like www) so I did some research.

约曼发电机预填充的.gitignore与bower_components文件,但它也预填充其他目录我认为将需要一个最终的应用程序(如www),所以我做了一些研究。

I discovered that www/index.html is a minified version of the app/index.html. The app directory and its contents (including bower_components) contains the source files needed for the output directory (www). You commit source directories into source-control (i.e. git) but not generated files (i.e. www). Package managers like bower and npm are meant to be used during the build/generation phase and their artifacts are not meant to be checked into source-control.

我发现 www/index.html 是 app/index.html 的缩小版本。app 目录及其内容(包括 bower_components)包含输出目录 (www) 所需的源文件。您将源目录提交到源代码管理(即 git)但不提交生成的文件(即 www)。像 bower 和 npm 这样的包管理器旨在在构建/生成阶段使用,并且它们的工件并不意味着要检查到源代码控制中。

Ultimately, the source that you check into git is the bare minimum configuration needed to build the rest of project for development or deployment purposes.

最终,您签入 git 的源代码是为开发或部署目的构建项目其余部分所需的最低配置。

回答by Joel Handwell

It is good to ignore /bower_componentsdir and check in only bower.jsonand bower-locker.bower.jsonfile if you create lock file using bower-lockerwritten by Shawn Lonas.

如果您使用由Shawn Lonas编写的bower-locker创建锁定文件,最好忽略/bower_componentsdir 并仅签入bower.jsonbower-locker.bower.json文件。

Before bower-locker created, there was disadvantage caused by an issue of bower not having shrinkwrap capabilitybut it can be mitigated by the above library.

在 bower-locker 创建之前,由于 bower没有收缩包装能力的问题导致了缺点,但可以通过上述库来缓解。

Run following commands to achieve it:

运行以下命令来实现它:

npm install bower-locker -g

or

或者

yarn global add bower-locker

then generate lock file based on existing bower.jsonfile by runing:

然后bower.json通过运行基于现有文件生成锁定文件:

bower-locker lock

The original bower.jsonfile will be re-named to bower-locker.bower.json

原始bower.json文件将被重命名为bower-locker.bower.json