简体   繁体   English

如何使用已安装的软件包更新bower.json?

[英]How to update bower.json with installed packages?

In my project I've installed bower components without save option. 在我的项目中,我安装了没有保存选项的bower组件。 Now, I would like update to bower.json ? 现在,我想更新到bower.json

How can I update bower.json with installed packages? 如何使用已安装的软件包更新bower.json?

Just list your dependencies: 只需列出您的依赖项:

bower list

Then you should run all install command with param '--save' like this: 然后你应该使用param'--save'运行所有install命令,如下所示:

bower install bootstrap --save

It's a hard work, but if you have a thousand dependencies, could you create a script to automatize the task. 这是一项艰苦的工作,但如果您有一千个依赖项,您是否可以创建一个脚本来自动执行该任务。

A little trick if you don't want to write a script for that: 如果您不想为此编写脚本,这是一个小技巧:

before doing anything rename your bower.json in bower2.json for example. 在做任何事情之前,例如在bower2.json中重命名你的bower.json。

then you can do a: 然后你可以做一个:

$ bower init

(automatically create a bower.json file). (自动创建bower.json文件)。

note that all questions should be pre-filled with your current config. 请注意,所有问题都应预先填入您当前的配置。

When it will ask you: 什么时候会问你:

set currently installed components as dependencies? 将当前安装的组件设置为依赖项? say yes, 说是的,

You now have all your dependencies in the new bower.json file (and you can check if everything is right with the old bower2.json) 你现在在新的bower.json文件中拥有了所有的依赖项 (你可以检查旧的bower2.json是否一切正常)

A bit arduous way is to run bower list , look for packages labeled extraneous and add those manually to the dependencies in the bower.json . 有点艰难的方法是运行bower list ,查找标记为无关的包,并将这些包手动添加到bower.json的依赖项中。

If there are a lot of extraneous packages, it might be easier to workaround this by running bower init and answering Yes to "set currently installed components as dependencies?". 如果有很多无关的软件包,通过运行bower init并回答“ 是”以“将当前安装的组件设置为依赖项?”来解决此问题可能更容易。 This will take your current bower.json , read it and then create new one using information from the old one. 这将使用您当前的bower.json ,读取它,然后使用旧信息创建新的bower.json So in an ideal case you will have the same file just with extraneous packages added. 所以在理想的情况下,只要添加了无关的包,你就会拥有相同的文件。

Warning : Firstly, there might be something lost in the process (eg devDependecies ). 警告 :首先,过程中可能会丢失某些内容(例如devDependecies )。 Secondly in the last version of bower (v1.2.7) this will not preserve current packages info! 其次在最后一个版本的凉亭(v1.2.7)中,这不会保留当前的包裹信息! I feel it is a bug. 我觉得这是一个错误。 However you can save the old file and (manually) merge it with the generated one. 但是,您可以保存旧文件并(手动)将其与生成的文件合并。

Also, you should ask for an option or something by opening a bower issue as this would be welcomed by many developers. 此外,你应该通过打开一个凉亭问题来寻求一个选项或者什么,因为这会受到许多开发者的欢迎。

You can use bower-check-updates (you need installed node.js on your machine): 您可以使用bower-check-updates (您需要在计算机上安装node.js):

bower-check-updates is a utility that automatically adjusts a bower.json with the latest version of all dependencies bower-check-updates是一个实用程序,可以使用所有依赖项的最新版本自动调整bower.json

bower-check-updates - is a fork of npm-check-updates , so it's all the same but updates bower.json , instead of package.json bower-check-updates - 是npm-check-updates的一个分支,所以它都是一样的但更新bower.json ,而不是package.json

npm install -g bower-check-updates
bower-check-updates -u
bower install 

This will install bower-check-updates globally, so you can launch it from anywhere. 这将全局安装bower-check-updates ,因此您可以从任何地方启动它。

PS for more information about npm-check-updates pleas see this topic PS有关更多信息,NPM-签更新认罪看到这个题目

If there aren't that many bower packages you have installed, try writing bower install [package_name] --save . 如果没有安装那么多的凉亭包,请尝试编写bower install [package_name] --save This will just update your bower.json file. 这只会更新你的bower.json文件。

bower-check-updates -u您必须运行bower install而不是npm install

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

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