为了账号安全,请及时绑定邮箱和手机立即绑定

让我们来学API-“REST”[工作流之bower]

Options(可选参数)
force
-f, --force

说明:Makes various commands more forceful(使各种命令更有力)

  • bower install --force re-installs all installed components. It also
    forces installation even when there are non-bower directories with
    the same name in the components directory. Adding --force also
    bypasses the cache, and writes to the cache anyway.(重新安装所有已安装的组件。即使在组件目录(bower_components \bootstrap(e.g.))中有具有相同的名称非bower目录,它也强制安装。添加--force 绕过高速缓存,并且无论如何写入高速缓存(本地缓存)。)
  • bower uninstall <package> --force continues uninstallation even
    after a dependency conflict(即使依赖冲突仍继续卸载)
  • bower register <package> --force bypasses confirmation. Login is
    still needed.(绕过确认。但登录是仍然需要。)

举个例子:

//安装:
//先进行安装(本地缓存中安装)
bower install jquery -S
//再进行强制安装(从网络中安装)
bower install jquery -f

图片描述

//卸载:(同时安装bootstrap)
//卸载jquery
bower uninstall jquery
//强制卸载jquery
bower uninstall jquery -f

bower uninstall jquery (冲突时,友好提示)
bower

bower uninstall jquery -f
图片描述

json
-j, --json

说明:Output consumable JSON(以JSON 格式输出)

举个栗子:对比输出格式(部分截图)

bower search jquery

bower

//JSON 格式
bower search jquery -j

bower

loglevel(日志级别)
-l, --loglevel

说明:What level of logs to report. Possible values: error, conflict, warn, action, info, debug(要报告的级别日志。 可能的值:错误,冲突,警告,操作,信息,调试)

举个栗子:级别由高到低,级别低包含级别高的输出信息

//错误
bower uninstall jquery -l=error
//冲突
bower uninstall jquery -l=conflict

bower

offline(离线)
-o, --offline

说明:Do not use network connection(不使用互联网连接)

举个栗子:

1. 安装jquery
bower uninstall jquery -S -f '&' bower install jquery -S

图片描述

2. 离线安装jquery(无校验)
bower uninstall jquery -S -f '&' bower insatll jquery -S -o

图片描述

quiet
-q, --quiet

说明:Only output important information. It is an alias for --loglevel=warn.(仅输出重要信息,它是--loglevel=wan的别名)

silent
-s, --silent

说明:Do not output anything, besides errors. It is an alias for --loglevel=error. Silent is also useful if you have private components that might leak credentials to your CI environment.(除了错误,不要输出任何东西。 它是--loglevel = error的别名。 如果您的私有组件可能泄露您的CI环境的凭据,则静默也很有用。)

verbose
-V, --verbose

说明:Makes output more verbose. It is an alias for --loglevel=debug.(使输出信息更详细,它是--loglevel=debug的别名。)

举个例子:对比输出“Available versions:”

bower info jquery
bower info jquery -V
allow-root
--allow-root

说明:Allows running commands as root. Bower is a user command, there is no need to execute it with superuser permissions. However, if you still want to run commands with sudo, use --allow-root option.(允许以root身份运行命令。 Bower是一个用户命令,没有必要用超级用户权限执行它。 但是,如果仍然要使用sudo运行命令,请使用--allow-root选项。)

Consuming a package(使用包)

You can use build tools to easily consume Bower packages.(您可以使用构建工具轻松使用Bower软件包。)

If you use bower list --paths or bower list --paths --json, you will get a simple name-to-path mapping:(如果你使用bower list --pathsbower list --paths --json ,你将得到一个简单的名称到路径映射:)

$ bower list --paths
# or
$ bower list --paths --json

bower

Every command supports the --json option that makes Bower output JSON. Command result is outputted to stdout and error/logs to stderr.(每个命令都支持--json选项,使Bower输出JSON。 命令结果输出到stdout(标准输出),错误/日志输出到stderr(标准错误)。)

Programmatic API(编程 API)
console.log('...')
Running on a continuous integration server(在连续集成服务器上运行)
console.log('...')
Non-interactive mode(非交互模式)

Bower works by default in interactive mode. There are few ways of disabling it:(默认情况下,Bower在交互模式下工作。 有几种方法禁用它:)

  • passing CI=true in environment(在环境中传递CI=true)
  • passing --config.interactive=false to Bower command(传递--config.interactive=false到Bower命令)
  • attaching a pipe to Bower (e.g. bower install | cat)(将管道连接到Bower(例如bower install | cat))
  • redirecting output to file (e.g. bower install > logs.txt)(将输出重定向到文件(例如bower install> logs.txt))
  • running Bower through its Programmatic API(通过其编程 API 运行Bower)

When interactive mode is disabled:(禁用交互模式时:)

  • bower init does not work(bower init 不工作)
  • bower register bypass confirmation(bower register 绕过确认)
  • bower login fails unless --token parameter is provided(bower login 失败,除非提供 --token参数)
  • bower install fails on resolution conflicts, instead of asking for
    choice(bower install在解决冲突时失败,而不是请求选择)
  • bower uninstall doesn’t ask for confirmation if dependency is to be
    removed( bower uninstall不要求确认是否要删除依赖关系)

举个栗子:

bower init --config.interactive=false

bower

Using local cache(使用本地缓存)

说明:Bower supports installing packages from its local cache – without an internet connection – if the packages were installed before.(Bower 支持从它的本地缓存中安装依赖包——没有网络连接——如果包之前安装了依赖包)

$ bower install <package> --offline

bower

The content of the cache can be listed with bower cache list:(缓存的内容可以用bower cache list列出:)

$ bower cache list

bower

The cache can be cleaned with bower cache clean:(缓存可以用bower cache clean清理:)

$ bower cache clean

bower

至此,bower 的API 就暂时结束了,难得自己看文档,也算一把成长史吧。接下来会学一下构建工具grunt中文站grunt英文站gulp中文站gulp英文站,包管理工具npmyarn,脚手架yeoman中文站yeoman英文站,自己都试着玩一把。

点击查看更多内容
1人点赞

若觉得本文不错,就分享一下吧!

评论

作者其他优质文章

正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦
今天注册有机会得

100积分直接送

付费专栏免费学

大额优惠券免费领

立即参与 放弃机会
意见反馈 帮助中心 APP下载
官方微信

举报

0/150
提交
取消