Cordova template解析

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的目录结构

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中的各个覆盖到你的项目中,然后实现模板技术。
所以自己下载的模板也只需要将相应的文件和文件夹覆盖过去就能用。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • jHipster - 微服务搭建 CC_简书[https://www.jianshu.com/u/be0d56c4...
    quanjj阅读 4,243评论 0 2
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,551评论 19 139
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 47,084评论 6 342
  • 写在开头 先说说为什么要写这篇文章, 最初的原因是组里的小朋友们看了webpack文档后, 表情都是这样的: (摘...
    Lefter阅读 10,689评论 4 31
  • 22年12月更新:个人网站关停,如果仍旧对旧教程有兴趣参考 Github 的markdown内容[https://...
    tangyefei阅读 35,298评论 22 257