How to rename react-native entry file (index.ios.js)

前端 未结 2 778
夕颜
夕颜 2020-12-16 15:04

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?

2条回答
  •  南方客
    南方客 (楼主)
    2020-12-16 15:32

    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

提交回复
热议问题