概述
Config.xml
存储着cordova应用的全局配置信息。
本文重点解释了config.xml中的几个常用配置,比如:access
allow-navigation
allow-intent
等。
更多信息请查看官方参考文档。
widget、name、description、author
- widget:
config.xml
中的根元素 - name:指定app名,它会显示在设备的主屏幕上
- description:app描述
- author:作者信息
content
指定app的根页面,默认是index.html
示例:
<widget ...> |
access
配置允许app发起的网络请求(images, XHRs, etc)地址
注意:没有配置access
标签时,,只有file://
urls被允许访问。但一般情况,app包含一个默认的<access origin="*">
标签。
示例:
<!--允许访问 google.com:--> |
更多请查看network-request-whitelist
allow-navigation
控制内部的WebView
可以加载的URL
,只适用于顶级导航。
默认情况下,只允许file://
类型的URLS访问。如果要加载其他的urls,需要配置<allow-navigation>
标签
<!-- 允许访问 example.com --> |
allow-intent
定义app可以要求操作系统打开的链接地址,默认,任何外部请求链接都被禁止。
示例:
<!-- 允许在浏览器中打开网址 --> |
engine
Specifies details about what platform to restore during a prepare.
plugin
Specifies details about what plugin to restore during a prepare. This element is automatically added to a project’s config.xml when a plugin is added using the –save flag.
variable
Persists the value of a CLI variable to be used when restoring a plugin during a prepare. This element is added to config.xml when a plugin that uses CLI variables is added using the –save flag.
示例:
<plugin name="cordova-plugin-device" spec="^1.1.0"> |
preference
Sets various options as pairs of name/value attributes. Each preference’s name is case-insensitive. Many preferences are unique to specific platforms, and will be indicated as such.
配置详情:https://cordova.apache.org/docs/en/6.x/config_ref/index.html#preference
feature
If you use the CLI to build applications, you use the plugin command to enable device APIs. This does not modify the top-level config.xml file, so the element does not apply to your workflow. If you work directly in an SDK and using the platform-specific config.xml file as source, you use the tag to enable device-level APIs and external plugins. They often appear with custom values in platform-specific config.xml files. See the API Reference for details on how to specify each feature
更多请参考:feature
platform
When using the CLI to build applications, it is sometimes necessary to specify preferences or other elements specific to a particular platform.
<platform name="android"> |
hook
Represents your custom script which will be called by Cordova when certain action occurs (for example, after plugin is added or platform prepare logic is invoked). This is useful when you need to extend default Cordova functionality.
更多请参考:https://cordova.apache.org/docs/en/6.x/config_ref/index.html#hook
<hook type="after_plugin_install" src="scripts/afterPluginInstall.js" /> |
date:2017-04-26 10:37:40
版本有变化时,配置可能发生变化,详细信息请参考官方文档