Dependency injection Bower只是关于自动安装依赖项吗?
鲍尔除了解决依赖关系之外,还做了其他事情吗?我正在努力理解它是如何被使用的,但我想我遗漏了一些要点 比如说,我有Bower软件包A,它依赖于Bower软件包B。在我的应用程序中,我只对软件包A感兴趣,因为这就是我要使用的。当然,这意味着两个包都必须加载到浏览器中,这样包A才能工作 使用Bower,我只需执行Dependency injection Bower只是关于自动安装依赖项吗?,dependency-injection,bower,Dependency Injection,Bower,鲍尔除了解决依赖关系之外,还做了其他事情吗?我正在努力理解它是如何被使用的,但我想我遗漏了一些要点 比如说,我有Bower软件包A,它依赖于Bower软件包B。在我的应用程序中,我只对软件包A感兴趣,因为这就是我要使用的。当然,这意味着两个包都必须加载到浏览器中,这样包A才能工作 使用Bower,我只需执行Bower安装a,然后在我的Bower\u组件中找到两个软件包a和B。到目前为止,太棒了 但是现在呢?我是否被迫(手动)确定A和B中的哪些文件需要加载到我的HTML页面中?我不认为可以通过we
Bower安装a
,然后在我的Bower\u组件中找到两个软件包a和B。到目前为止,太棒了
但是现在呢?我是否被迫(手动)确定A和B中的哪些文件需要加载到我的HTML页面中?我不认为可以通过web直接访问完整的bower_组件
,因此我必须手动配置我的Grunt(或其他)构建文件来复制相关文件
我错过了什么?如果我上面写的是真的,那么当我仍然需要了解所有隐式依赖项时,使用Bower有什么意义呢?Bower管理依赖项,如果您使用--save(或-s)标志,它会将正确的文件添加到HTML中。如果index.html不在同一目录中,则需要在bower.json中设置appPath
$ bower help install
Usage:
bower install [<options>]
bower install <endpoint> [<endpoint> ..] [<options>]
Options:
-F, --force-latest Force latest version on conflict
-h, --help Show this help message
-p, --production Do not install project devDependencies
-S, --save Save installed packages into the project's bower.json dependencies
-D, --save-dev Save installed packages into the project's bower.json devDependencies
Additionally all global options listed in 'bower help' are available
Description:
Installs the project dependencies or a specific set of endpoints.
Endpoints can have multiple forms:
- <source>
- <source>#<target>
- <name>=<source>#<target>
Where:
- <source> is a package URL, physical location or registry name
- <target> is a valid range, commit, branch, etc.
- <name> is the name it should have locally.
```
$bower帮助安装
用法:
凉亭安装[]
凉亭安装[..][]
选项:
-F、 --部队关于冲突的最新版本
-h、 --帮助显示此帮助消息
-p、 --生产部门不安装项目专用设备
-S、 --将已安装的包保存到项目的bower.json依赖项中
-D、 --将安装的软件包保存到项目的bower.json devdependences中
此外,“bower帮助”中列出的所有全局选项都可用
说明:
安装项目依赖项或一组特定的终结点。
端点可以有多种形式:
-
- #
- =#
哪里:
-是包URL、物理位置或注册表名
-是有效范围、提交、分支等。
-是它在本地应具有的名称。
```
您实际上没有遗漏任何内容。Bower不负责加载依赖项,只负责安装它们。加载它们是你必须自己做的事情。此外,人们加载依赖项的方式也多种多样;最常见的可能是Require.JS、Browserify(信用太少,无法发布链接)和index.html页面中包含的纯脚本。所以,基本上你有几个选择
index.html
页面中添加
标记,或者在使用Require.js时添加依赖项注册,类似于app.js
。请注意,这一步意味着您必须手动查看每个依赖项,阅读文档或bower.json
文件,以找出可传递的依赖项和文件路径bower.json
文件来自动完成至于公开允许访问“bower_组件”,我发现这是最常见的方法。您希望阻止访问哪些内容?我本人也是bower的新用户。据我所知,简短的回答是:是的,bower旨在下载依赖项,但是,除了能够将bower_components目录配置为您喜欢的任何内容之外,其想法是bower安装的组件根本不会被您编辑,如果您想手动包含它们,您可以键入
bower list --paths
这将列出从依赖项(在相对URL中)需要包含的所有文件
您还可以使用(npm安装-g bower安装程序),它允许您将所需文件复制到任何您喜欢的路径。例如,使用细粒度控件,或选择缩小版本
下面是一个示例输出
C:\Users\german\test>bower install bootstrap
bower bootstrap#* not-cached git://github.com/twbs/bootstrap.git#*
bower bootstrap#* resolve git://github.com/twbs/bootstrap.git#*
bower bootstrap#* download https://github.com/twbs/bootstrap/archive/v3.3.4.tar.gz
bower bootstrap#* extract archive.tar.gz
bower bootstrap#* resolved git://github.com/twbs/bootstrap.git#3.3.4
bower jquery#>= 1.9.1 not-cached git://github.com/jquery/jquery.git#>= 1.9.1
bower jquery#>= 1.9.1 resolve git://github.com/jquery/jquery.git#>= 1.9.1
bower jquery#>= 1.9.1 download https://github.com/jquery/jquery/archive/2.1.4.tar.gz
bower jquery#>= 1.9.1 extract archive.tar.gz
bower jquery#>= 1.9.1 resolved git://github.com/jquery/jquery.git#2.1.4
bower bootstrap#~3.3.4 install bootstrap#3.3.4
bower jquery#>= 1.9.1 install jquery#2.1.4
bootstrap#3.3.4 bower_components\bootstrap
└── jquery#2.1.4
jquery#2.1.4 bower_components\jquery
C:\Users\german\test>bower list --paths
jquery: 'bower_components/jquery/dist/jquery.js',
bootstrap: [
'bower_components/bootstrap/less/bootstrap.less',
'bower_components/bootstrap/dist/css/bootstrap.css',
'bower_components/bootstrap/dist/js/bootstrap.js',
'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.eot',
'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.svg',
'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf',
'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff',
'bower_components/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2'
]
之后
bootstrap[]根据bower_components/bootstrap/bower.json显示了我需要包含的所有文件
main:[]
部分
希望这有帮助!干杯
bower list --paths