项目结构

Cordova项目结构其实非常简单易懂,简单来说,其实Cordova的作用就是把一些网页(或者一个单页应用)用WebView封装成一个APP。

工程目录
|_hooks           用于扩展Cordova命令,很少用到
|_node_modules    Node的依赖包
|_platforms       特定平台的代码部分
|_plugins         插件
|_www             前端相关的HTML、CSS、JavaScript等
|_config.xml      Cordova配置文件
|_package.json    Node工程配置文件

config.xml

我们编写Android原生工程时,都知道一个APP项目有包名、版本号,项目名、描述信息等,在Cordova工程中,这些内容是在config.xml中进行配置的。下面例子是创建工程后的默认内容:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloCordova</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html" />
    <plugin name="cordova-plugin-whitelist" spec="1" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

其中,widget里的id就是工程包名,version是版本号,name是项目名,其余内容也都比较好理解,这里就不多介绍了。

作者:Gacfox
版权声明:本网站为非盈利性质,文章如非特殊说明均为原创,版权遵循知识共享协议CC BY-NC-ND 4.0进行授权,转载必须署名,禁止用于商业目的或演绎修改后转载。