How to use a Cordova App Templates!
三種方式
$ cordova create hello com.example.hello HelloWorld --template <npm-package-name>
$ cordova create hello com.example.hello HelloWorld --template <git-remote-url>
$ cordova create hello com.example.hello HelloWorld --template <path-to-template>
如果需要知道他是怎么使用的辫塌,那么我們就要先了解一下teplate package
的目錄結(jié)構(gòu)
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
的內(nèi)容
var path = require('path');
module.exports = module.exports = {
dirname: path.join(__dirname, 'template_src')
};
然后在看一下package.json
的內(nèi)容
{
"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"
}
發(fā)先其實(shí)就是項(xiàng)目的配置項(xiàng),跟自己創(chuàng)建的項(xiàng)目下的package.json
是一樣一樣的
然后template_src
文件夾下包含哪些呢?
config.xml hooks res www/
沒錯看到這里想必大家都明白了--teplate
是真么用的了囚灼。
他就是講后面帶的teplate_package
中的各個覆蓋到你的項(xiàng)目中丹禀,然后實(shí)現(xiàn)模板技術(shù)放闺。
所以自己下載的模板也只需要將相應(yīng)的文件和文件夾覆蓋過去就能用拜英。