Sometimes it's useful to rebuild an entire site and force bower to reinstall new versions of all the packages in bower.json.
有时候,重新构建整个站点并强制bower重新安装bower.json中所有包的新版本是很有用的。
However, there doesn't seem to be any way of doing that:
然而,似乎没有办法做到这一点:
Attempt #1:
$ bower uninstall
bower not-installed 0
Nope, that only works on a package-by-package basis, even though a clean 'bower install' uses bower.json.
不,这只适用于按包安装,即使一个干净的“bower install”使用bower.json。
Attempt #2:
$ bower install -f -l 0
$
Nope, despite '-f', this does absolutely nothing if the dependencies are met.
不,除了'-f'之外,如果满足了依赖项,那么它什么都不起作用。
Attempt #3:
$ rm -r bower_components
$
! Ah victory! ... wait, what's this?
!胜利啊!…等等,这是什么?
rm: bower_components: No such file or directory
Oh darn, there's a .bowrc in this project that sets the directory to install things to.
天哪,这个项目中有一个。bowrc设置了要安装东西的目录。
My current terrible solution:
Run custom script that:
运行自定义脚本:
- Parse .bowerrc if one exists
- Load the directory if one is specified in the json block
- If the directory currently exists...
- ...recursively delete the directory.
It works, I suppose, but it's pretty annoying to have to setup repeatedly.
我想这是可行的,但是重复设置是很烦人的。
Am I missing something?
我遗漏了什么东西?
Is there not just a simple bower command to delete the local installed modules?
难道不存在一个简单的bower命令来删除本地安装的模块吗?
Seems like really basic functionality I would expect bower uninstall to do.
看起来真的是最基本的功能,我希望bower uninstall做。
(This isn't really a very javascript question, but I'll happily accept something that hooks into the bower module somehow to make this happen in a simple node script)
(这并不是一个非常javascript的问题,但是我很乐意接受在一个简单的节点脚本中以某种方式连接到bower模块的东西)
Context
Edit: If you want 'motivation' for such a task, it's this: We have a jenkins server that builds our projects and runs tests. However, periodically it fails for no obvious reason; investigating, it's almost always because jenkins is using a previous copy of the repository with just a git-pull to update to the most recent version before building and running tests; as a result, the previous bower_components directory is there, and it is full of cached copies of the various components.
编辑:如果你想要这样一个任务的“动机”,那就是:我们有一个jenkins服务器来构建我们的项目并运行测试。然而,它周期性地失败,没有明显的原因;调查中,这几乎总是因为jenkins使用的是一个以前的存储库拷贝,在构建和运行测试之前,只需要一个git-pull就可以更新到最近的版本;因此,以前的bower_component目录就在那里,它包含了各种组件的缓存副本。
Here a few example of things which are #@$@#$'d and require bower to be run again as a forced install:
这里有一些例子,它们是#@$@#$'d,并要求bower作为强制安装再次运行:
1) Some idiot (>_> fitvids) deletes the previous tagged release of a project.
1)某个白痴(>_> fitvids)删除项目先前标记的版本。
2) Some project has dropped off of bower / moved its github page
2)一些项目已经从bower / move它的github页面上删除
3) Some project (>_> jquery) has changed the way the files are laid out in a non-major version revision.
3)一些项目(>_> jquery)改变了文件在非主流版本修订中的布局方式。
I realize that the 'correct' solution to this problem is: fix jenkins so it creates a new temporary directory for each build. ...but that's not in my control.
我意识到这个问题的“正确”解决方案是:修复jenkins,这样它就可以为每个构建创建一个新的临时目录。但那不在我的控制范围内。
So, as a build step, I need to automate a way to delete the bower components and force them to all be reinstalled; either as a grunt task (part of the build) or a jenkins build step. However, remember from (3) above, that our projects use .bowerrc, so it's not as simple as simply deleting a folder.
因此,作为构建步骤,我需要自动地删除bower组件并强制它们全部重新安装;要么作为繁重的任务(构建的一部分),要么作为jenkins的构建步骤。但是,请记住,从上面的(3)中,我们的项目使用.bowerrc,所以这并不像简单地删除一个文件夹那么简单。
It would be great if I could uninstall all the existing bower components as a pre-build step to make this work.
如果我可以卸载所有现有的bower组件作为预构建步骤来完成这项工作,那就太棒了。
So... back to the question: Can this be done with bower?
所以…回到这个问题:这能用鲍尔完成吗?
8 个解决方案
#1
147
Updated Answer
更新后的答案
If you're trying to update all of your packages, use
如果要更新所有包,请使用
$ bower update
Original Answer
原来的答案
Go to your bower.json file and remove all of the components, or libraries, that you want to uninstall from devDependencies.
去你的凉亭。json文件并删除希望从devDependencies中卸载的所有组件或库。
After you have removed the ones you want gone, execute -
在你把你想要的删除后,执行-
$ bower prune
-
start with -
开始- - - - - -
"devDependencies": { "angular": "~1.2.15", "angular-ui-router": "~0.2.10", "moment": "~2.5.1" }
-
remove angular references from file -
从文件-删除角度引用
"devDependencies": { "moment": "~2.5.1" }
-
execute
执行
$ bower prune
-
watch your angular dependencies get uninstalled
注意你的角依赖被卸载
#2
10
how about
如何
- edit the bower.json
- 编辑bower.json
- 'rm -Rf bower_components/*'
- “rm射频bower_components / *”
- bower install
- 鲍尔安装
I was trying to upgrade to polymer 0.2.4 from 0.2.3. I can't seem to find a quick way to uninstall a set of dependencies. So I just manually removed those polymer* dir under bower_components. But for some reason bower kept remembering I had 0.2.3 installed event with bower.json modified. A 'rm -Rf bower_component/*' seems to do the tricks.
我试图从0.2.3升级到0.2.4。我似乎找不到快速卸载一组依赖项的方法。我只是在bower_components下手工去掉了这些聚合物。但是出于某种原因,鲍尔一直记得我用鲍尔安装了0.2.3个事件。json修改。一个“rm -Rf bower_component/*”似乎可以做到这一点。
#3
6
Actually I do something a little bit tricky but it works for me:
实际上我做了一件有点棘手的事,但对我来说是行得通的:
for package in $(ls your_bower_components_folder); do bower uninstall "$package"; done;
- 以$表示的包(ls your_bower_components_folder);鲍尔卸载”美元包”;完成;
bower install
- 鲍尔安装
#4
5
Uninstalling Packages
卸载程序包
To remove a package you can use the uninstall command followed by the name of the package you wish to remove.
要删除一个包,可以使用uninstall命令,后面跟着要删除的包的名称。
bower uninstall
鲍尔卸载
It’s possible to remove multiple packages at once by listing the package names.
通过列出包名,可以同时删除多个包。
bower uninstall jquery modernizr sass-bootstrap
bower卸载jquery modernizr sass-bootstrap
#5
0
Adapting Jumar Polanco's answer to use it in Powershell, it is possible to programmatically uninstall bower components in the following way:
将Jumar Polanco的答案应用到Powershell中,可以通过编程方式以以下方式卸载bower组件:
In the Powershell interface, navigate to the location where bower.json and the bower_components folder is located. Usually is the root app folder.
在Powershell界面中,导航到鲍尔所在的位置。位于json和bower_components文件夹中。通常是根应用程序文件夹。
Then you can run:
然后您可以运行:
foreach($package in ls bower_components){bower uninstall $package}
foreach($package in ls bower_components){bower uninstall $package}
Depending on what the packages dependencies are, it may be required to pay extra attention to the process, as some prompts which require extra input (Y/n) to continue the process may arise (such as dependency conflicts).
根据包的依赖关系是什么,可能需要对流程给予额外的关注,因为可能会出现一些需要额外输入(Y/n)来继续该流程的提示(例如依赖冲突)。
#6
0
I don't know what build tools you use, but if it includes Grunt with grunt-bowercopy, you could use the clean
option. It removes the bower_components folder (or whatever you've configured it to use) after copying out the required files.
我不知道您使用的是什么构建工具,但是如果它包含了咕哝和咕哝-bowercopy,您可以使用clean选项。在复制所需的文件之后,它删除了bower_components文件夹(或者您已经配置的任何文件)。
Ideally, I'd prefer something that didn't require me to re-download all the dependencies with each build, but just the ones where doing a fresh install would find a newer version.
理想情况下,我更喜欢不需要在每次构建中重新下载所有依赖项的东西,而只需要重新安装一个新版本就可以了。
I'm looking for a better solution to this as well, so I'll update if I find one.
我也在寻找更好的解决方案,所以如果我找到了,我会更新。
#7
0
I've been using nombom
to do this (as a bonus, it also re-installs your npm packages from scratch):
我一直在使用nombom来做这个(作为奖励,它还重新安装您的npm包):
https://www.npmjs.com/package/nombom
https://www.npmjs.com/package/nombom
#8
0
This is what ended up working for me via Windows cmd prompt:
这就是我通过Windows cmd提示符获得的结果:
forfiles /p .\bower_components /c "cmd /c cd .. && bower uninstall @fname"
#1
147
Updated Answer
更新后的答案
If you're trying to update all of your packages, use
如果要更新所有包,请使用
$ bower update
Original Answer
原来的答案
Go to your bower.json file and remove all of the components, or libraries, that you want to uninstall from devDependencies.
去你的凉亭。json文件并删除希望从devDependencies中卸载的所有组件或库。
After you have removed the ones you want gone, execute -
在你把你想要的删除后,执行-
$ bower prune
-
start with -
开始- - - - - -
"devDependencies": { "angular": "~1.2.15", "angular-ui-router": "~0.2.10", "moment": "~2.5.1" }
-
remove angular references from file -
从文件-删除角度引用
"devDependencies": { "moment": "~2.5.1" }
-
execute
执行
$ bower prune
-
watch your angular dependencies get uninstalled
注意你的角依赖被卸载
#2
10
how about
如何
- edit the bower.json
- 编辑bower.json
- 'rm -Rf bower_components/*'
- “rm射频bower_components / *”
- bower install
- 鲍尔安装
I was trying to upgrade to polymer 0.2.4 from 0.2.3. I can't seem to find a quick way to uninstall a set of dependencies. So I just manually removed those polymer* dir under bower_components. But for some reason bower kept remembering I had 0.2.3 installed event with bower.json modified. A 'rm -Rf bower_component/*' seems to do the tricks.
我试图从0.2.3升级到0.2.4。我似乎找不到快速卸载一组依赖项的方法。我只是在bower_components下手工去掉了这些聚合物。但是出于某种原因,鲍尔一直记得我用鲍尔安装了0.2.3个事件。json修改。一个“rm -Rf bower_component/*”似乎可以做到这一点。
#3
6
Actually I do something a little bit tricky but it works for me:
实际上我做了一件有点棘手的事,但对我来说是行得通的:
for package in $(ls your_bower_components_folder); do bower uninstall "$package"; done;
- 以$表示的包(ls your_bower_components_folder);鲍尔卸载”美元包”;完成;
bower install
- 鲍尔安装
#4
5
Uninstalling Packages
卸载程序包
To remove a package you can use the uninstall command followed by the name of the package you wish to remove.
要删除一个包,可以使用uninstall命令,后面跟着要删除的包的名称。
bower uninstall
鲍尔卸载
It’s possible to remove multiple packages at once by listing the package names.
通过列出包名,可以同时删除多个包。
bower uninstall jquery modernizr sass-bootstrap
bower卸载jquery modernizr sass-bootstrap
#5
0
Adapting Jumar Polanco's answer to use it in Powershell, it is possible to programmatically uninstall bower components in the following way:
将Jumar Polanco的答案应用到Powershell中,可以通过编程方式以以下方式卸载bower组件:
In the Powershell interface, navigate to the location where bower.json and the bower_components folder is located. Usually is the root app folder.
在Powershell界面中,导航到鲍尔所在的位置。位于json和bower_components文件夹中。通常是根应用程序文件夹。
Then you can run:
然后您可以运行:
foreach($package in ls bower_components){bower uninstall $package}
foreach($package in ls bower_components){bower uninstall $package}
Depending on what the packages dependencies are, it may be required to pay extra attention to the process, as some prompts which require extra input (Y/n) to continue the process may arise (such as dependency conflicts).
根据包的依赖关系是什么,可能需要对流程给予额外的关注,因为可能会出现一些需要额外输入(Y/n)来继续该流程的提示(例如依赖冲突)。
#6
0
I don't know what build tools you use, but if it includes Grunt with grunt-bowercopy, you could use the clean
option. It removes the bower_components folder (or whatever you've configured it to use) after copying out the required files.
我不知道您使用的是什么构建工具,但是如果它包含了咕哝和咕哝-bowercopy,您可以使用clean选项。在复制所需的文件之后,它删除了bower_components文件夹(或者您已经配置的任何文件)。
Ideally, I'd prefer something that didn't require me to re-download all the dependencies with each build, but just the ones where doing a fresh install would find a newer version.
理想情况下,我更喜欢不需要在每次构建中重新下载所有依赖项的东西,而只需要重新安装一个新版本就可以了。
I'm looking for a better solution to this as well, so I'll update if I find one.
我也在寻找更好的解决方案,所以如果我找到了,我会更新。
#7
0
I've been using nombom
to do this (as a bonus, it also re-installs your npm packages from scratch):
我一直在使用nombom来做这个(作为奖励,它还重新安装您的npm包):
https://www.npmjs.com/package/nombom
https://www.npmjs.com/package/nombom
#8
0
This is what ended up working for me via Windows cmd prompt:
这就是我通过Windows cmd提示符获得的结果:
forfiles /p .\bower_components /c "cmd /c cd .. && bower uninstall @fname"