DEV Community

Cover image for React Native CI/CD build speed improved by 22% with one line of code
Davyd NRB
Davyd NRB

Posted on • Updated on

React Native CI/CD build speed improved by 22% with one line of code

Every release build of React Native uses terser to reduce the size of your JavaScript. And it operation can be omitted for Staging/Beta builds.

Add an if statement using the env variable in the android/app/build.gradle file:

project.ext.react = [
  enableHermes: true,
  extraPackagerArgs: System.getenv("NO_MINIFY_JS") ? ["--minify", "false", "--reset-cache", "false"]: []
]
Enter fullscreen mode Exit fullscreen mode

Open Xcode for iOS, choose "Build Phases" => "Bundle React Native code and images" and add the following code at the beginning:

export EXTRA_PACKAGER_ARGS="" 
# ^^^ Can be added you default args (for example '--sourcemap-output')

if [ "$NO_MINIFY_JS" == "1" ]; then
    export EXTRA_PACKAGER_ARGS="$EXTRA_PACKAGER_ARGS --minify false --reset-cache false"
fi
# ...
Enter fullscreen mode Exit fullscreen mode

Add NO_MINIFY_JS=1 environment variable, to CI for Non-Prod builds after that.

The results is depicted in the screenshot up top (minus 4min).


Please don't hesitate to ask questions in the comments section if you have any.

MurAmur ©

Top comments (0)