Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
418 views
in Technique[技术] by (71.8m points)

javascript - 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.

Can I change this file's name and if so, how?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...