Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova hooks order

On the Cordova website a see a long list of hooks in alphabetical order, but what is the correct order in which they trigger and get executed?

I'm trying to add the cordova.js script to the index.html file's head before build/compile.

What happens first between before_build and before_compile, and why? What's the difference between the terms build and compile here?

Does build mean copying all the assets before compile the platform code? So my hook should be in the before_build directory?

Please confirm or correct me if I'm wrong.

Also a correct order of the hooks will be helpful to everybody since the documentation is unclear :)

EDIT:

Does cordova-cli automatically add the cordova.js script for me eventually, in the case it's missing? Because I was testing the hook, and even if it didn't work the script is already present in the html file.

like image 219
Zorgatone Avatar asked Nov 11 '15 09:11

Zorgatone


People also ask

What are hooks in Cordova?

Cordova Hooks represent special scripts which could be added by application and plugin developers or even by your own build system to customize cordova commands. Cordova hooks allow you to perform special activities around cordova commands.

What is Cordova Android?

Cordova Android is an Android application library that allows for Cordova-based projects to be built for the Android Platform. Cordova based applications are, at the core, applications written with web technology: HTML, CSS and JavaScript. Apache Cordova is a project of The Apache Software Foundation (ASF).


1 Answers

Compile is the native compilation step while prepare is when Cordova does all the copying of preferences and assets. Build is a shortcut for running both of these. You can see this is the order that hooks are fired. (Tested on Cordova 5.4.0)

On Cordova build:

before_build
before_prepare
after_prepare
before_compile
after_compile
after_build

On Cordova prepare:

before_prepare
after_prepare

On Cordova compile:

before_compile
after_compile

On Cordova run:

before_run
before_prepare
after_prepare
after_run

Interestingly run appears to fire the prepare hooks, but not the compile (or build) hooks. This could just be a bug.

like image 176
Connor Avatar answered Sep 23 '22 00:09

Connor