Cordova template解析

How to use a Cordova App Templates!

三种方式

$ cordova create hello com.example.hello HelloWorld --template 
$ cordova create hello com.example.hello HelloWorld --template 
$ cordova create hello com.example.hello HelloWorld --template 

如果需要知道他是怎么使用的,那么我们就要先了解一下teplate package的目录结构

template_package/
├── package.json      (optional; needed to publish template on npm)
├──   index.js        (required)
└── template_src/     (required)
    └── CONTENTS OF APP TEMPLATE

注意: index.js 需要为package.json 和teplate.js输出一个参考

看一下index.js的内容

var path = require('path');

module.exports = module.exports = {
    dirname: path.join(__dirname, 'template_src')
};

然后在看一下package.json的内容

{
  "name": "cordova-app-hello-world",
  "version": "3.11.1-dev",
  "description": "This is the hello world app used by the `cordova create` command.",
  "repository": {
    "type": "git",
    "url": "https://git-wip-us.apache.org/repos/asf/cordova-app-hello-world.git"
  },
  "main": "index.js",
  "keywords": [
    "ecosystem:cordova",
    "cordova:template"
  ],
  "author": "Apache Software Foundation",
  "license": "Apache-2.0"
}

发先其实就是项目的配置项,跟自己创建的项目下的package.json是一样一样的
然后template_src文件夹下包含哪些呢?

config.xml   hooks   res   www/

没错看到这里想必大家都明白了--teplate是真么用的了。
他就是讲后面带的teplate_package中的各个覆盖到你的项目中,然后实现模板技术。
所以自己下载的模板也只需要将相应的文件和文件夹覆盖过去就能用。

你可能感兴趣的:(Cordova template解析)