Running a prebuild script in react mode

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

on creation. I'm guessing there is a way to do this, but I'm not familiar with how react-native

/ gradle / Xcode builds.

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

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

      

and /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 he didn't do anything. I guess I need to add a third link somewhere, but I can't figure out where.

+3


source to share


1 answer


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

For example, below I am running. / scripts / script-to-run-before-RN-build.sh before React initiates the bundler to do 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"
}

      

0


source







All Articles