Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a script pre-build in react-native

I have some resource files that I need to copy from /app/resources to both /android/app/src/main/ress/raw and /ios/<project>/resources when I build. I assume there's a way to do this, but I'm not familiar with how react-native/Gradle/XCode builds.

For gradle, I tried adding to /android/app/build.gradle

task copySounds(type: Copy) {
    from '../../app/resources/sounds/*'
    into 'src/main/res/raw/'
}

and to /android/.idea/workspace.xml

<project version="4">
  // ...
  <component name="GradleLocalSettings">
    // ...
    <option name="availableTasks">
      <map>
        <entry>
          // ...
          <value>
            <list>
              // ...
              <ExternalTaskPojo>
                <option name="linkedExternalProjectPath" value="$PROJECT_DIR$" />
                <option name="name" value="copySounds" />
              </ExternalTaskPojo>
              // ...
            </list>
          </value>
        </entry>
        // ...
      </map>
    </option>
    // ...
  </component>
</project>

but it didn't seem to do anything. My guess is I need to add a third reference somewhere, but I can't figure out where.

like image 209
dx_over_dt Avatar asked Mar 30 '17 17:03

dx_over_dt


People also ask

How do I run a script in react native?

This could be done in the scripts section of package. json at the root of your project. For instance, below I am running ./scripts/script-to-run-before-RN-build.sh before React Native packager is being called to perform the build.

What is a post build script?

The post-build script runs after the build has finished and copied all the necessary artifacts to the output directory. The post-build script will run even if the build fails.


1 Answers

This could be done in the scripts section of package.json at the root of your project.

For instance, below I am running ./scripts/script-to-run-before-RN-build.sh before React Native packager is being called to perform the build.

"scripts": {
      "start": "npm run pre-packager && node node_modules/react-native/local-cli/cli.js start",
      "pre-packager": "./scripts/script-to-run-before-RN-build.sh"
}
like image 186
Olivier Avatar answered Oct 05 '22 22:10

Olivier