Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bower installs several files. why and how can I change it?

I am using bower to install dependencies for my project(I know there is yeoman but I am using bower). After setting up component.json file, when I do bower install it installs dependencies to correct directory but it install lots of other unnecessary files with it too. Now I want bower to install the specific file which is needed for example jquery.js, backbone.js and underscore.js and nothing else. How can I do it with bower?

like image 349
26ph19 Avatar asked Apr 21 '13 08:04

26ph19


People also ask

How do I update bower dependencies?

Installing dependencies with one command First, you'll want to delete the bower_components folder. Bower will then look through your bower. json and download all dependencies for you. After it's done, you'll be able to find your dependencies back in the bower_components folder.

How does bower install work?

Bower doesn't concatenate or minify code or do anything else - it just installs the right versions of the packages you need and their dependencies. To get started, Bower works by fetching and installing packages from all over, taking care of hunting, finding, downloading, and saving the stuff you're looking for.

Why is bower used?

Bower is a package manager, like npm, which manages frameworks, libraries, assets, and utilities, installs them, and makes sure they are up to date. Traditionally, many web development projects combined npm and Bower. npm was used to manage back-end dependencies, while Bower was used for front-end dependencies.


3 Answers

I recently wrote up a possible solution to this problem and will highlight the main points below.

If you know you want a specific file from a particular package, it is easy enough to tell bower to only grab that file. For instance, with normalize.css, the only file that I care about is, well, normalize.css. So instead of typing:

bower install --save normalize-css 

I can be more specific and tell bower to just download the css file:

bower install --save https://raw.github.com/necolas/normalize.css/master/normalize.css 

That, of course, will always grab the latest version of normalize from the repository's master branch when bower install is invoked for your project. If, however, I want to make sure I always get the 3.0.0 version of normalize, then I can dig through the releases/history to find the appropriate URL and viola:

bower install --save http://necolas.github.io/normalize.css/3.0.0/normalize.css 
like image 180
jbranchaud Avatar answered Sep 29 '22 22:09

jbranchaud


You can check out bower-installer.

bower list --path usually tells about the main js file in the package, which bower-installer conveniently picks up and exports only those files to your asset directories. You can then use this directory instead and ignore the bower_components dir.

like image 37
kdabir Avatar answered Sep 30 '22 00:09

kdabir


It's up to the package authors to specify what files to exclude from the package using the ignore property. For now just include the files you want in the your app/website and ignore the rest.

like image 22
Sindre Sorhus Avatar answered Sep 30 '22 00:09

Sindre Sorhus