cordova create

cordova create command

Synopsis

Create the directory structure for the Cordova project in the specified path.

Syntax

cordova create path [id [name [config]]] [options]
Value Description
path Directory which should not already exist. Cordova will create this directory. For more details on the directory structure, see below.
id Default: io.cordova.hellocordova
Reverse domain-style identifier that maps to id attribute of widget element in config.xml. This can be changed but there may be code generated using this value, such as Java package names. It is recommended that you select an appropriate value.
name Default: HelloCordova
Application's display title that maps name element in config.xml file. This can be changed but there may be code generated using this value, such as Java class names. The default value is HelloCordova, but it is recommended that you select an appropriate value.
config JSON string whose key/values will be included in <path>/.cordova/config.json

Options

Option Description
--template Use a custom template located locally, in NPM, or GitHub.
--copy-from\ --src
--link-to Symlink to specified www directory without creating a copy.

Directory structure

Cordova CLI works with the following directory structure:

myapp/
|-- config.xml
|-- hooks/
|-- merges/
| | |-- android/
| | |-- windows/
| | |-- ios/
|-- www/
|-- platforms/
| |-- android/
| |-- windows/
| |-- ios/
|-- plugins/
  |--cordova-plugin-camera/

config.xml

Configures your application and allows you to customize the behavior of your project. See also config.xml reference documentation

www/

Contains the project's web artifacts, such as .html, .css and .js files. As a cordova application developer, most of your code and assets will go here. They will be copied on a cordova prepare to each platform's www directory. The www source directory is reproduced within each platform's subdirectory, appearing for example in platforms/ios/www or platforms/android/assets/www. Because the CLI constantly copies over files from the source www folder, you should only edit these files and not the ones located under the platforms subdirectories. If you use version control software, you should add this source www folder, along with the merges folder, to your version control system.

platforms/

Contains all the source code and build scripts for the platforms that you add to your project.

WARNING: When using the CLI to build your application, you should not edit any files in the /platforms/ directory unless you know what you are doing, or if documentation specifies otherwise. The files in this directory are routinely overwritten when preparing applications for building, or when plugins are re-installed.

plugins/

Any added plugins will be extracted or copied into this directory.

hooks/

This directory may contains scripts used to customize cordova-cli commands. Any scripts you add to these directories will be executed before and after the commands corresponding to the directory name. Useful for integrating your own build systems or integrating with version control systems.

Refer to Hooks Guide for more information.

merges/

Platform-specific web assets (HTML, CSS and JavaScript files) are contained within appropriate subfolders in this directory. These are deployed during a prepare to the appropriate native directory. Files placed under merges/ will override matching files in the www/ folder for the relevant platform. A quick example, assuming a project structure of:

merges/
|-- ios/
| -- app.js
|-- android/
| -- android.js
www/
-- app.js

After building the Android and iOS projects, the Android application will contain both app.js and android.js. However, the iOS application will only contain an app.js, and it will be the one from merges/ios/app.js, overriding the "common" app.js located inside www/.

Version control

It is recommended not to check in platforms/ and plugins/ directories into version control as they are considered a build artifact. Instead, you should save the platform/plugin spec in the config.xml and they will be downloaded when on the machine when cordova prepare is invoked.

Examples

  • Create a Cordova project in myapp directory using the specified ID and display name:

    cordova create myapp com.mycompany.myteam.myapp MyApp
    
  • Create a Cordova project with a symlink to an existing www directory. This can be useful if you have a custom build process or existing web assets that you want to use in your Cordova app:

    cordova create myapp --link-to=../www
    
doc_cordova
2017-01-31 03:40:04
Comments
Leave a Comment

Please login to continue.