Reputation: 49853
Can anybody explain me what is the real difference between these commands and what they specifically do:
cordova build
cordova run
cordova compile
cordova prepare
Reading from the doc doesn't help much https://cordova.apache.org/docs/en/4.0.0/guide/cli/#link-5
I have doubts because, for example, the command build
and the command run
both seems to build the app...
Upvotes: 1
Views: 408
Reputation: 4333
Cordova has two separate phases in it's build process, Prepare
and Compile
.
Prepare basically copies the www
folder into the platform specified, and any additional platform steps needed.
Compile will compile the app into a binary, (apk for android, .app for ios, etc)
The other commands are simply shortcuts for joining commands. The reason it is split out so much is so you can make hooks into before/after each step, if you need to run any custom code.
Build will run the the Prepare
and Compile
steps for you, since this is the most common usecase.
Run will call build
before installing the finished app (and launching the emulator if --device
wasn't specified). Looking at their docs I just learned you can run --nobuild
to skip the build step!
Reading their docs was actually really helpful, so I would recommend doing that as well. https://cordova.apache.org/docs/en/latest/reference/cordova-cli/index.htm
Upvotes: 0
Reputation: 1575
The order should be prepare -> compile -> build -> run. You can read in reverse second time to understand it better.
cordova run - If you have already build the app, it simply runs. if you have not built the app then cordova will first build it and then run it. You cannot run a native app if it is not built (unlike web apps in browser).
cordova build - Before you run you must build. As cordova supports multiple platforms you may specify iOS as target for the build phase. during build phase the necessary packaging is done for the targeted platform.
cordova compile - A compile command is meant to check if your written code is perfect and no syntax error (or a reference error) exists.
cordova prepare - A prepare is the phase before compilation. As cordova need to first convert your code to target the specific (iOS/android) platform, sometime a few developers optimize their code by first writing the code which is common for all platforms and then choosing prepare and writing platform specific code for iOS or Android for their ease. This step is also done in a situation when you do not find a good solution in cordova and want to write your own code to glue natively in platform.
Upvotes: 1