简体   繁体   English

Bower下载整个jQuery

[英]Bower downloads entire jQuery

I have Bower version 1.3.1. 我有Bower版本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: 我得到了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? 我可以以某种方式安装依赖只下载jquery.min.js?

bower doesn't work like that. bower不是那样的。 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. 问题是, bower不知道包装的哪些部分已被使用或未被使用,因此必须下载整个包装。

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. 现在,你可以从源代码获取你想要的页面( wget ,下载等)而不用担心其余部分,但这可能比它的价值更麻烦,因为你必须确保页面没有链接到其他页面。 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 ? 你不能直接从bower那里做到这一点,所以你必须自己设置它,那时为什么要使用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. 如果你不关心空间问题,你也可以安装整个软件包,但只使用它的一部分(如,参考页面,如<link href="/path/to/package/page_in_package" /> ) 。 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 eg <link /> s inside it). 我不相信这会对带宽等产生任何影响,因为整个软件包都在您的服务器上,但客户端只会请求一个页面(尽管该页面可能会导致客户端请求其他页面,例如<link />在其内部或多个)。

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. 最后,您可以安装整个软件包然后删除它的一部分,但您必须知道要删除哪些部分,并且bower可能会尝试重新下载这些文件/文件夹。 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> . 据我所知,通过实验, bower不会尝试重新下载你删除的任何内容,只要该软件包与bower.json版本相同,除非你告诉它bower installbower install <any package> It won't even redownload them if you say bower update <whatever> . 如果你说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? 如果您的bower.json没有该软件包, bower将永远不会删除该文件夹中的任何内容,但如果另一个软件包需要此软件包的不同版本,它将无法帮助您,这就是bower的全部原因不是吗?

This is not about bower but jQuery itself. 这不是关于凉亭,而是jQuery本身。 Since jQuery doesn't have a separated repository for distribution on bower so you get the whole project. 由于jQuery没有用于在bower上分发的独立存储库,因此您可以获得整个项目。 For example, Angular has an official one where Bootstrap has an unofficial one where you can get only production-ready files. 例如,Angular有一个正式的 ,其中Bootstrap有一个非官方的 ,你只能获得生产就绪的文件。

update: there is actually the component/jquery which is exactly what you want: a shim project of jquery. 更新:实际上有一个组件/ jquery正是你想要的:一个jquery的shim项目。 it doesn't show up in $ bower search jquery command but you can install using repo url. 它不会显示在$ bower search jquery命令中,但您可以使用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 . 您可以尝试使用bower-installer https://github.com/blittle/bower-installer

It is a tool for installing bower dependencies that won't include entire repos. 它是一个安装bower依赖项的工具,不包括整个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. 如果某个库在bower.json配置中不包含“main”文件,或者您希望获得不同的文件,则可以在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. 我还应该注意它仍然在bower_components中下载整个repo,因为它首先使用bower install然后将“main”文件移动到目标目录。

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. 也许,这并没有涵盖你不需要除了一个特定文件之外的任何其他文件的确切用例,但如果你将它与gulp混合并用它来删除大的bower_components /之后它会很有用。 bower-installer完成。

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

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

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