- Overview
- Installation
- Creating an App
- Project Structure
- CLI Commands
- Platform Support
- Platform Pinning
- Version Management
- Hooks
- Android
- iOS
- Electron
- Icons
- Splash Screen
- Security
- Privacy
- Allow List
- Data Storage
- Create a Plugin
- Android
- iOS
- Use Plugman
- Config.xml API
- Plugin.xml API
- Cordova JavaScript API
- Third-party Tools
- App Templates
- Next Steps
- Battery Status
- Camera
- Device
- Dialogs
- File
- Geolocation
- Inappbrowser
- Media
- Media Capture
- Network Information
- Screen Orientation
- Browser Splashscreen
- Statusbar
- Vibration
- Embed Cordova in native apps
App Templates
Use a Template
Templates allow you to use preexisting code to jumpstart your project.
Find a template to create your app from by seaching for the keyword cordova:template
on npm. You can also use local templates on your computer, or a Git repository.
After locating a template you wish to use. Create your project using that template, by specifying the --template
flag during the create
command, followed by your template source.
Creating a cordova project from an NPM package, Git repository, or local path:
cordova create hello com.example.hello HelloWorld --template <npm-package-name|git-repo|local-dir-path>
After succesfully using a template to create your project, you'll want to indicate the platforms that you intend to target with your app. Go into your project folder and add platforms.
Create a Template
Begin by creating a cordova app that will become the basis for your template. Then you'll take the contents of your app and put them into the following structure. When your template is used, all of the contents within template_src
will be used to create the new project, so be sure to include any necessary files in that folder. Reference this example for details.
template_package
├── package.json (for your template package to be published on npm)
├── index.js (required)
└── template_src (required - contains template files)
├── package.json
├── config.xml
└── (files and folders that make up the template)
NOTE:
index.js
should export a reference totemplate_src
andpackage.json
should referenceindex.js
. See the example for details on how that is done.
To finish off your template, edit package.json
to contain the keyword "cordova:template"
.
{
...
"keywords": [
"ecosystem:cordova",
"cordova:template"
]
...
}
Congrats! You've made a template for creating a Cordova project. Share your template on npm so that everyone can benefit from your hard work.