Sudhir Jonathan
Sudhir Jonathan

Reputation: 17526

Where and how does React Native resolve .android.js and .ios.js files?

The React Native packager has a feature where it automatically chooses between *.android.js and *.ios.js files depending on the environment being built for. I'd like to see if the same mechanism can be used for *.web.js files as well, allowing a web application to be built in the same repository as well.

I'm trying to figure out how this works and where in the code it's implemented, but I can't seem to find it. Is there a way to just set an ENV variable to web and have it work?

Upvotes: 1

Views: 1504

Answers (1)

Fomahaut
Fomahaut

Reputation: 1212

It's not a part of React framework, it's in your iOS/Android project files.

iOS/AppDelegate.m line 34:

jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"];

android/app/src/main/java/com/rn/MainActivity.java line 24-31:

mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(BuildConfig.DEBUG)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();

You can change the setting in React-Native generator, but I think using Webpack is the better way if you want pack a index.web file.

Upvotes: 1

Related Questions