Skip to main content

Run Scripts During The Build

During the Appflow build process, it might be necessary to run custom scripts and it is important to know what will and won't run.

Capacitor Hooks

Capacitor hooks are specified in your package.json to execute scripts around the execution of capacitor commands. Appflow specifically executes npx cap sync for native builds so the capacitor:sync:before and capacitor:sync:after hooks can be used in the Appflow build process.

Cordova Hooks

Cordova hooks are specified in your config.xml and when used with the Cordova CLI will execute scripts. Appflow however uses Gym to compile your Application, so Cordova hooks will not run with the exception of after_platform_add and after_prepare.

Ionic Hooks

Ionic has a set of hooks which are specified in your package.json to execute scripts during certain events. These hooks do not run with Appflow.

Npm Pre & Post Scripts

Npm will execute scripts before and after a command is run (documented here). If you create a script called prebuild or postbuild in your package.json these will run before and after the build step in Appflow.

note

The postbuild script of package.json will run after your web source code is compiled and not after your native code is compiled.

Conclusion

If you are looking to run scripts during the Appflow build process you can use npm pre & post scripts, the after_platform_add and after_prepare hooks for cordova projects, and the capacitor:sync:before and capacitor:sync:after hooks for Capacitor projects. For additional automation options look at the Appflow Automation feature.