2

RE (don't have enough experience points to reply there): "In my bundle command for my production build I tell it to generate a source map" How to add sourcemap in React Native for Production?

In Xcode Version 7.3 beta 3, I went to [My Project] > Build Phases > Bundle React Native code and images

Under: export NODE_BINARY=node ../node_modules/react-native/packager/react-native-xcode.sh

I added: cd /Users/andresn/dev/[My Project] react-native bundle --platform ios --entry-file index.ios.js --dev false --bundle-output ./ios/main.jsbundle --assets-dest ./ios --sourcemap-output ./sourcemap.js

Is something like this what he meant, or is there a more proper way of doing this?

Community
  • 1
  • 1
Andres Narvaez
  • 516
  • 5
  • 11
  • Note: you need a semicolon or line break after that first cd: cd /Users/andresn/dev/[My Project]; react-native bundle --platform ios --entry-file index.ios.js --dev false --bundle-output ./ios/main.jsbundle --assets-dest ./ios --sourcemap-output ./sourcemap.js – Andres Narvaez Mar 15 '16 at 18:05
  • Hey @Andres Narvaez did you manage to get this to work for you? – Brien Crean Apr 26 '16 at 22:32
  • @brien.crean yeah, no problems to date after my last comment. – Andres Narvaez May 02 '16 at 03:20

2 Answers2

3

A generic solution based on what you've already said:

export NODE_BINARY=node

if [ "${CONFIGURATION}" = "Release" ]
then
  cd "${PROJECT_DIR}/../"
  react-native bundle --platform ios --entry-file index.ios.js --dev false --bundle-output ./ios/main.jsbundle --assets-dest ./ios --sourcemap-output ./ios/main.jsbundle.map
else
  ../node_modules/react-native/scripts/react-native-xcode.sh
fi

Be sure to add the assets and main.jsbundle.map to your iOS project then create your release build again.

Bruno Lemos
  • 8,847
  • 5
  • 40
  • 51
Luke Rhodes
  • 293
  • 3
  • 13
3

I ended up using the following script in Bundle React Native code and images:

export NODE_BINARY=node
if [ "${CONFIGURATION}" = "Release" ]
then ../sourcemap.sh
else ../node_modules/react-native/scripts/react-native-xcode.sh
fi

Then in the project directory's root, I'm using the following sourcemap.sh script which generates a source map file in the ./ios directory:

#!/bin/bash
$NODE_BINARY ../node_modules/react-native/local-cli/cli.js bundle --platform ios --entry-file ./index.ios.js --dev false --bundle-output ./main.jsbundle --assets-dest ./ --sourcemap-output ./main.jsbundle.map
Bruno Lemos
  • 8,847
  • 5
  • 40
  • 51
peerless
  • 558
  • 3
  • 11