如何重命名react-native条目文件(index.ios.js) [英] How to rename react-native entry file (index.ios.js)
问题描述
当我初始化一个react-native项目时, index.ios.js
被创建为项目条目文件。
<是否可以更改此文件的名称,如果是,如何更改?
当您启动react-native应用程序时,您将会请参阅React Packager输出的此消息:
在端口8081上运行打包器
然后:
在$中查找JS文件b $ b / Users / gbirman / gil / mapily
React packager ready。
到目前为止,打包者已经编译了你的JS文件并用<$ c $为它们提供服务c> .js 扩展名重命名为 .bundle
。例如,您的 index.io.js
文件已编译并提供:
http:// localhost:8081 / index.ios.bundle
如果你添加了另一个文件 foo.js
与 index.ios.js
在同一目录中,打包者将从以下位置提供服务:
http:// localhost:8081 / foo.bundle
您可以通过在浏览器中打开该网址来确认这一点。
现在回答你的问题,你的项目有一个带 iOS / AppDelegate.m 文件https://github.com/facebook/react-native/blob/72d3d724a3a0c6bc46981efd0dad8f7f61121a47/Examples/SampleApp/iOS/AppDelegate.m#L29\">以下行:
jsCodeLocation = [NSURL URLWithString:@http:// localhost:8081 / index.ios.bundle];
...如您所见,它加载 index.ios。束
。您可以将路径/文件名更改为您想要的任何内容,但最好坚持使用建议的方法来命名您的条目文件 index.io.js
When I init a react-native project, index.ios.js
is created as project entry file.
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:
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
. For example, your index.io.js
file is compiled and served from:
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:
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:
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];
... as you can see, it loads the 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
这篇关于如何重命名react-native条目文件(index.ios.js)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!