Learn how to use the EAS Build lifecycle hooks with npm to customize your build process.
There are five EAS Build lifecycle npm hooks that you can set in your package.json. See the Android build process and iOS build process docs to get a better understanding about the internals of the build process.
eas-build-pre-install
- executed before EAS Build runs npm install
.eas-build-post-install
- the behavior depends on the platform and project type:
npm install
and npx expo prebuild
(if needed)npm install
, npx expo prebuild
(if needed), and pod install
.eas-build-on-success
- this hook is triggered at the end of the build process if the build was successful.eas-build-on-error
- this hook is triggered at the end of the build process if the build failed.eas-build-on-complete
- this hook is triggered at the end of the build process. You can check the build's status with the EAS_BUILD_STATUS
environment variable. It's either finished
or errored
.Below is an example of how your package.json can look with lifecycle hooks:
{
"name": "my-app",
"scripts": {
"eas-build-pre-install": "echo 123",
"eas-build-post-install": "echo 456",
"eas-build-on-success": "echo 789",
"eas-build-on-error": "echo 012",
"start": "expo start",
"test": "jest"
},
"dependencies": {
"expo": "~46.0.0"
// ...
}
}
If you would like to run a script (or some part of a script) only for iOS builds or only for Android builds, you can fork the behavior depending on the platform within the script. See examples for common ways to do this through a shell script or a Node script below.
package.json
and shell script{
"name": "my-app",
"scripts": {
"eas-build-pre-install": "./pre-install",
"start": "expo start"
// ...
},
"dependencies": {
// ...
}
}
#!/bin/bash
# This is a file called "pre-install" in the root of the project
if [[ "$EAS_BUILD_PLATFORM" == "android" ]]; then
echo "Run commands for Android builds here"
elif [[ "$EAS_BUILD_PLATFORM" == "ios" ]]; then
echo "Run commands for iOS builds here"
fi
package.json
and Node script{
"name": "my-app",
"scripts": {
"eas-build-pre-install": "node pre-install.js",
"start": "expo start"
// ...
},
"dependencies": {
// ...
}
}
// This is a file called "pre-install.js" in the root of the project
if (process.env.EAS_BUILD_PLATFORM === 'android') {
console.log('Run commands for Android builds here');
} else if (process.env.EAS_BUILD_PLATFORM === 'ios') {
console.log('Run commands for iOS builds here');
}