How to update bower.json with installed packages?

后端 未结 6 1100
遇见更好的自我
遇见更好的自我 2021-01-29 22:28

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

How can I update b

相关标签:
6条回答
  • 2021-01-29 23:09

    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

    0 讨论(0)
  • 2021-01-29 23:14

    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.

    0 讨论(0)
  • 2021-01-29 23:19

    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)

    0 讨论(0)
  • 2021-01-29 23:27

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

    0 讨论(0)
  • 2021-01-29 23:28

    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.

    0 讨论(0)
  • 2021-01-29 23:30

    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.

    0 讨论(0)
提交回复
热议问题