How to update bower.json with installed packages?

随声附和 提交于 2019-12-20 08:23:08

问题


In my project I've installed bower components without save option. Now, I would like update to bower.json?

How can I update bower.json with installed packages?


回答1:


Just list your dependencies:

bower list

Then you should run all install command with param '--save' like this:

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.




回答2:


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.

then you can do a:

$ bower init

(automatically create a bower.json file).

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)




回答3:


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.

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?". This will take your current bower.json, read it and then create new one using information from the old one. 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 (e.g. devDependecies). Secondly in the last version of bower (v1.2.7) this will not preserve current packages info! 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.




回答4:


You can use bower-check-updates (you need installed node.js on your machine):

bower-check-updates is a utility that automatically adjusts a bower.json with the latest version of all dependencies

bower-check-updates - is a fork of npm-check-updates, so it's all the same but updates bower.json, instead of 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.

P.S. for more information about npm-check-updates pleas see this topic




回答5:


If there aren't that many bower packages you have installed, try writing bower install [package_name] --save. This will just update your bower.json file.




回答6:


After bower-check-updates -u you must run bower install instead of npm install



来源:https://stackoverflow.com/questions/20279792/how-to-update-bower-json-with-installed-packages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!