[英]How to rename react-native entry file (index.ios.js)
When I init a react-native project, index.ios.js
is created as project entry file. 当我初始化一个react-native项目时,
index.ios.js
被创建为项目条目文件。
Can I change this file's name and if so, how? 我可以更改此文件的名称吗?如果是,如何更改?
When you start a react-native app you'll see this message output by the React Packager: 当您启动react-native应用程序时,您将看到React Packager输出的此消息:
Running packager on port 8081
and then: 然后:
Looking for JS files in
/Users/gbirman/gil/mapily
React packager ready.
By this point, the packager has compiled your JS files and is serving them with the .js
extension renamed to .bundle
. 到目前为止,打包程序已编译了您的JS文件,并将
.js
扩展名重命名为.bundle
。 For example, your index.io.js
file is compiled and served from: 例如,您的
index.io.js
文件是通过以下方式编译和提供的:
http://localhost:8081/index.ios.bundle
If you added another file foo.js
in the same directory as index.ios.js
, the packager would serve it from: 如果添加其他文件
foo.js
在同一目录index.ios.js
,包装者会从服务于它:
http://localhost:8081/foo.bundle
You can confirm this by opening that url in your browser. 您可以通过在浏览器中打开该网址来确认这一点。
Now to answer your question, your project has an iOS/AppDelegate.m
file with the following line : 现在回答您的问题,您的项目有一个
iOS/AppDelegate.m
文件,其中包含以下行 :
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
... as you can see, it loads the index.ios.bundle
. ...正如您所看到的,它加载了
index.ios.bundle
。 You can change the path/filename there to whatever you want, but it's probably best to stick with the recommended approach of naming your entry file index.io.js
您可以将路径/文件名更改为您想要的任何内容,但最好坚持使用建议的方法来命名您的条目文件
index.io.js
Suppose you've moved your index.ios.js
into a folder called dist
. 假设您已将
index.ios.js
移动到名为dist
的文件夹中。 You need to do two things 你需要做两件事
For your development environment: Update jsBundleURLForBundleRoot
in AppDelegate.m
to match your updated path. 对于您的开发环境:在
AppDelegate.m
更新jsBundleURLForBundleRoot
以匹配您更新的路径。
For your release bundle: Open your Xcode project. 对于您的发行包:打开您的Xcode项目。 You'll need to update the Bundle React Native code and images task under Build Phases for your project.
您需要在项目的Build Phases下更新Bundle React Native代码和图像任务。 Update the shell script in this section to look like below:
更新本节中的shell脚本,如下所示:
export NODE_BINARY=node ../node_modules/react-native/packager/react-native-xcode.sh dist/index.ios.js
react-native-xcode.sh
accepts the ENTRY_FILE
as an optional first argument, defaulting to index.ios.js
if none is found. react-native-xcode.sh
接受ENTRY_FILE
作为可选的第一个参数,如果没有找到,则默认为index.ios.js
。
Updated Build Phases Example 更新了构建阶段示例
Reference - react-native/scripts/react-native-xcode.sh 参考 - react-native / scripts / react-native-xcode.sh
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.