Question

I have Bower version 1.3.1.

I've defined following dependencies:

"dependencies": {
"angular" : "1.2.13",
"angular-cookies" : "1.2.13",
"angular-resource" : "1.2.13",
"angular-route" : "1.2.13",
"bootstrap" : "3.1.1",
"jqplot" : "b882a2044fe03e4009f49b990155a8e1686a2d67",
"jquery" : "2.0.0",
"requirejs" : "2.1.11",
"requirejs-text" : "2.0.10",
"spin.js" : "1.3.3"
}

After I do:

bower install. I get entire project for jQuery:

drwxr-xr-x  6 root root   4096 Apr  5 13:41 .
drwxr-xr-x 12 root root   4096 Apr  5 13:41 ..
-rw-rw-r--  1 root root   6353 Apr 18  2013 AUTHORS.txt
-rw-r--r--  1 root root    512 Apr  5 13:41 .bower.json
-rwxrwxr-x  1 root root    212 Apr 18  2013 bower.json
drwxrwxr-x  2 root root   4096 Apr  5 13:41 build
-rwxrwxr-x  1 root root    212 Apr 18  2013 component.json
-rwxrwxr-x  1 root root    881 Apr 18  2013 composer.json
-rw-rw-r--  1 root root   8134 Apr 18  2013 CONTRIBUTING.md
-rw-rw-r--  1 root root    595 Apr 18  2013 .editorconfig
-rw-rw-r--  1 root root     26 Apr 18  2013 .gitattributes
-rw-rw-r--  1 root root    178 Apr 18  2013 .gitignore
-rw-rw-r--  1 root root    171 Apr 18  2013 .gitmodules
-rw-rw-r--  1 root root  15021 Apr 18  2013 Gruntfile.js
-rwxrwxr-x  1 root root 240196 Apr 18  2013 jquery.js
-rwxrwxr-x  1 root root  16178 Apr 18  2013 jquery-migrate.js
-rwxrwxr-x  1 root root   7086 Apr 18  2013 jquery-migrate.min.js
-rwxrwxr-x  1 root root  83095 Apr 18  2013 jquery.min.js
-rw-rw-r--  1 root root    242 Apr 18  2013 .jshintrc
-rw-rw-r--  1 root root   4418 Apr 18  2013 .mailmap
-rw-rw-r--  1 root root   1099 Apr 18  2013 MIT-LICENSE.txt
-rw-rw-r--  1 root root    883 Apr 18  2013 package.json
-rw-rw-r--  1 root root  12447 Apr 18  2013 README.md
drwxrwxr-x  2 root root   4096 Apr  5 13:41 speed
drwxrwxr-x  4 root root   4096 Apr  5 13:41 src
drwxrwxr-x  5 root root   4096 Apr  5 13:41 test

Can I somehow install dependency to download only jquery.min.js?

Was it helpful?

Solution

bower doesn't work like that. You either install the whole package or none of the package. The issue is that bower doesn't know what parts of the package are or aren't used, so it has to download the whole thing.

Now, you could get the page you want from source (wget, downloading it, etc) & not worry about the rest, but this might be more trouble than it's worth, as you'd have to be sure the page doesn't link to other pages. You can't do this directly from bower, either, so you'd have to set it up yourself, and at that point why use bower?

You can also install the whole package but only use part of it (as in, reference a page, as in <link href="/path/to/package/page_in_package" />), if you don't care about space issues. I don't believe this will have any effect on bandwidth, etc., as the whole package is on your server, but the client would only request that one page (although the page may cause the client to request other pages with e.g. <link />s inside it).

Finally, you could install the whole package then delete parts of it, but you have to know what parts to delete, and bower may try to redownload those files/folders. As far as I can tell through experimentation, bower won't attempt to re-download anything you delete, as long as the package is the same version as the one in your bower.json, unless you tell it bower install or bower install <any package>. It won't even redownload them if you say bower update <whatever>. If you don't have the package in your bower.json, bower will never delete anything in that folder, but it won't help you if another package needs a different version of this package, either, which is the whole reason for bower, isn't it?

OTHER TIPS

This is not about bower but jQuery itself. Since jQuery doesn't have a separated repository for distribution on bower so you get the whole project. For example, Angular has an official one where Bootstrap has an unofficial one where you can get only production-ready files.

update: there is actually the component/jquery which is exactly what you want: a shim project of jquery. it doesn't show up in $ bower search jquery command but you can install using repo url.

$ bower install https://github.com/components/jquery

however, this repo will probably be deleted soon.

You can try using bower-installer https://github.com/blittle/bower-installer .

It is a tool for installing bower dependencies that won't include entire repos. It extracts only "main" files in a directory you configure it to use. If a certain library doesn't contain "main" files(s) in bower.json configuration, or you want different files to be grabed, you can configure it in your bower.json.

I should also note that it still downloads the whole repo in bower_components because it first uses bower install and then moves the "main" files to a target directory.

Maybe, this doesn't cover you exact use-case in which you don't want any other files to be downloaded except one specific file, but it can be useful if you mix it with gulp and use it to delete large bower_components/ after bower-installer finishes.

More resources: https://scotch.io/tutorials/only-grab-the-files-you-need-while-using-bower http://strangemilk.com/bower-installer/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top