Hooks are pieces of code that Cordova CLI executes at certain points in your Cordova/Ionic application build. Hooks can be used for example to manipulate files in our project, automatically add plugins into your application or as in the example above check for code errors in your files.
The following hook types are supported and execution order is quite self-explanatory according to the name.
after_build after_compile after_docs after_emulate after_platform_add after_platform_rm after_platform_ls after_plugin_add after_plugin_ls after_plugin_rm after_plugin_search after_prepare after_run after_serve before_build before_compile before_docs before_emulate before_platform_add before_platform_rm before_platform_ls before_plugin_add before_plugin_ls before_plugin_rm before_plugin_search before_prepare before_run before_serve pre_package/ <-- Applicable to Windows 8 and Windows Phone only. This hook is deprecated.
Hooks could be defined in project's
<hook> elements, for example:
<hook type="after_build" src="scripts/appAfterBuild.js" />
As a plugin developer you can define hook scripts using
<hook> elements in a
plugin.xml like this:
<hook type="after_build" src="scripts/afterBuild.js" />
before_plugin_uninstall plugin hooks will be fired exclusively for the plugin being installed/uninstalled.
Note: Placing hooks in the
root/hooks directory is considered deprecated in favor of the hook elements in
plugin.xml. If you however use this approach remember to set execute rights to the files in the
Documentation for Cordova Hooks can be found here.