Cordova HooksWe can define the Cordova Hooks as the special scripts that allow a user to automate the basic features of your Cordova project by using the Cordova CLI. It is a piece of code that can be added by any application, plugin developers, or even by your own build system to improve the development/deployment lifecycle of Apache Cordova application. However, these scripts of code are executed by the Cordova CLI at certain points in your Cordova application build for customizing the Cordova commands. These scripts of code can be run many times in the build process. We can relate these hooks as application activities such as before_build, after_build, etc. Furthermore, it may be related to our application plugins such as before_plugin_add, after_plugin_add, etc. In general, the "hook" folder is available in our project's root folder that consists of different subfolders like after_platform_add, after_build, before_platform_add, before_build, etc. For running hook scripts, it is being used. The supported hook types are as follows:
Ways to define hooksConfig.xmlThe <hook> elements is used to define the Hooks in project's config.xml file for example: Plugin hooks (plugin.xml)For defining the hook scripts as a plugin developer, we need to use the essential <hook> elements in the plugin.xml file: Via/hooks directory (Deprecated)To execute any custom actions occurred when fired the corresponding hook type, we need to use the hook type. This hook type is used for the subfolder inside 'hooks' directory. Here, we place our script file. It is necessary for the specified action. Example: Note that your scripts must be executable. Order of Hooks executionBased on Hooks Definition The Hook scripts can be defined by adding the scripts to the special predefined folder i.e. via configuration files config.xml and plugin.xml, or hooks. However, you should know that the order of hooks is executed serially. Based on internal order of the execution We can fix the internal order of execution to the hooks. Suppose, if the hooks are connected with before_compile, after_compile, before_prepare, after_prepare, before_build and after_build, then a build command will run to execute the hooks in the below order:
before_build
before_prepare after_prepare before_compile after_compile after_build
Next TopicCordova Plugins
|