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.
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.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With