ionic-frameworkIonic CLI hooks


Remarks

Introduction

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.

Note: It is highly recommended writing your hooks using Node.js so that they are cross-platform but you can write them also for example in Javascript.

Hook types

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.

Ways to define hooks:

Hooks could be defined in project's config.xml using <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_install, after_plugin_install, 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 config.xml and plugin.xml. If you however use this approach remember to set execute rights to the files in the root/hooks folder.

Documentation for Cordova Hooks can be found here.