I've been trying to research this but haven't found much information on it. I'm investigating writing React in Typescript in code that can be both run on mobile but also the web. I've seen some tricks like aliasing 'react-native' with 'react-native-web', but it doesn't necessarily work in all cases since the APIs aren't 100% 1-to-1. I've also come across some articles that mention being able to write platform specific code in '.native.ts' and '.web.ts' files. One example is this StackOverflow question. So questions I have:
If I were to start with a clean project, could someone show me what packages to add and how to configure it to recognize writing '.native.ts' files for mobile and '.web.ts' files for web?
In this type of project, are both native and web built into the same bundle?
If so, how does consuming (running on a mobile device or on a desktop browser) know which files (native or web) to load?
I've read things like react-native-web's multi-platform page, and looked into Expo, but I'm looking for a simple way for a package to have both native and web code and allow it to be consumed by either platform. That's why I'm most interested in the answer to my first question above. Maybe have a sample app that demonstrates how it's done.
Thanks in advance for any responses!
- Steve