Skip to content

Commit be70e32

Browse files
franticfacebook-github-bot-7
authored andcommitted
Generate bundle and assets when building via Xcode
Summary: This integrates React Native into Xcode's build process, which lets us automatically handle bundling and packaging image assets. Tested the script via https://github.com/frantic/ReactNativeAssetsExample Loaded from packager: <img width="432" alt="screen shot 2015-10-19 at 3 11 12 pm" src="https://cloud.githubusercontent.com/assets/192222/10593447/be5bc7e8-7678-11e5-8c70-ecc2a1ee24fc.png"> Loaded from offline bundle: <img width="432" alt="screen shot 2015-10-19 at 3 10 58 pm" src="https://cloud.githubusercontent.com/assets/192222/10593448/be5d5194-7678-11e5-8b02-d492a26cfb81.png"> Android: <img width="639" alt="screen shot 2015-10-19 at 3 11 20 pm" src="https://cloud.githubusercontent.com/assets/192222/10593449/be5de2d0-7678-11e5-8d3c-0378fc447f15.png"> Closes #3523 Reviewed By: mkonicek Differential Revision: D2557923 Pulled By: frantic fb-gh-sync-id: 19957e255993696e793b0162662772efd89f5c1a
1 parent aff4cfb commit be70e32

File tree

6 files changed

+62
-23
lines changed

6 files changed

+62
-23
lines changed

local-cli/__tests__/generators-test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ describe('React Yeoman Generators', function() {
208208

209209
it('creates files', function() {
210210
assert.file([
211-
'ios/main.jsbundle',
212211
'ios/TestAppIOS/AppDelegate.h',
213212
'ios/TestAppIOS/AppDelegate.m',
214213
'ios/TestAppIOS/Base.lproj/LaunchScreen.xib',

local-cli/generator-ios/index.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ var yeoman = require('yeoman-generator');
1515
module.exports = yeoman.generators.NamedBase.extend({
1616
writing: function() {
1717
var templateVars = {name: this.name};
18-
// SomeApp/ios
19-
this.fs.copyTpl(
20-
this.templatePath(path.join('main', '**')),
21-
this.destinationPath('ios'),
22-
templateVars
23-
);
2418
// SomeApp/ios/SomeApp
2519
this.fs.copyTpl(
2620
this.templatePath(path.join('app', '**')),

local-cli/generator-ios/templates/app/AppDelegate.m

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,8 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
3535

3636
/**
3737
* OPTION 2
38-
* Load from pre-bundled file on disk. To re-generate the static bundle
39-
* from the root of your project directory, run
40-
*
41-
* $ react-native bundle --minify
42-
*
43-
* see http://facebook.github.io/react-native/docs/running-on-device-ios.html
38+
* Load from pre-bundled file on disk. The static bundle is automatically
39+
* generated by "Bundle React Native code and images" build step.
4440
*/
4541

4642
// jsCodeLocation = [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"];

local-cli/generator-ios/templates/main/main.jsbundle

Lines changed: 0 additions & 8 deletions
This file was deleted.

local-cli/generator-ios/templates/xcodeproj/project.pbxproj

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10-
008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */ = {isa = PBXBuildFile; fileRef = 008F07F21AC5B25A0029DE68 /* main.jsbundle */; };
1110
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
1211
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; };
1312
00C302E81ABCBA2D00DB3ED1 /* libRCTImage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302C01ABCB91800DB3ED1 /* libRCTImage.a */; };
@@ -334,6 +333,7 @@
334333
13B07F871A680F5B00A75B9A /* Sources */,
335334
13B07F8C1A680F5B00A75B9A /* Frameworks */,
336335
13B07F8E1A680F5B00A75B9A /* Resources */,
336+
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */,
337337
);
338338
buildRules = (
339339
);
@@ -505,14 +505,31 @@
505505
isa = PBXResourcesBuildPhase;
506506
buildActionMask = 2147483647;
507507
files = (
508-
008F07F31AC5B25A0029DE68 /* main.jsbundle in Resources */,
509508
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */,
510509
13B07FBD1A68108700A75B9A /* LaunchScreen.xib in Resources */,
511510
);
512511
runOnlyForDeploymentPostprocessing = 0;
513512
};
514513
/* End PBXResourcesBuildPhase section */
515514

515+
/* Begin PBXShellScriptBuildPhase section */
516+
00DD1BFF1BD5951E006B06BC /* Bundle React Native code and images */ = {
517+
isa = PBXShellScriptBuildPhase;
518+
buildActionMask = 2147483647;
519+
files = (
520+
);
521+
inputPaths = (
522+
);
523+
name = "Bundle React Native code and images";
524+
outputPaths = (
525+
);
526+
runOnlyForDeploymentPostprocessing = 0;
527+
shellPath = /bin/sh;
528+
shellScript = "../node_modules/react-native/packager/react-native-xcode.sh";
529+
showEnvVarsInLog = 1;
530+
};
531+
/* End PBXShellScriptBuildPhase section */
532+
516533
/* Begin PBXSourcesBuildPhase section */
517534
00E356EA1AD99517003FC87E /* Sources */ = {
518535
isa = PBXSourcesBuildPhase;

packager/react-native-xcode.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/bin/bash
2+
# Copyright (c) 2015-present, Facebook, Inc.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree. An additional grant
7+
# of patent rights can be found in the PATENTS file in the same directory.
8+
9+
# Bundle React Native app's code and image assets.
10+
# This script is supposed to be invoked as part of Xcode build process
11+
# and relies on envoronment variables (including PWD) set by Xcode
12+
13+
case "$CONFIGURATION" in
14+
Debug)
15+
DEV=true
16+
;;
17+
Release)
18+
DEV=false
19+
;;
20+
"")
21+
echo "$0 must be invoked by Xcode"
22+
exit 1
23+
;;
24+
*)
25+
echo "Unsupported value of \$CONFIGURATION=$CONFIGURATION"
26+
exit 1
27+
;;
28+
esac
29+
30+
# Xcode project file for React Native apps is located in ios/ subfolder
31+
cd ..
32+
33+
set -x
34+
DEST=$CONFIGURATION_BUILD_DIR/$UNLOCALIZED_RESOURCES_FOLDER_PATH
35+
36+
react-native bundle \
37+
--entry-file index.ios.js \
38+
--platform ios \
39+
--dev $DEV \
40+
--bundle-output "$DEST/main.jsbundle" \
41+
--assets-dest "$DEST"

0 commit comments

Comments
 (0)