mjohnston / react-native-webpack-server

Build React Native apps with Webpack
MIT License
933 stars 84 forks source link

Add platform-dependent module resolution #120

Closed elliottsj closed 8 years ago

elliottsj commented 8 years ago

As described by @philikon in https://github.com/mjohnston/react-native-webpack-server/pull/111#discussion_r43030879:

Another thing to consider is the platform-based module resolution. If I do require('./foobar') with the React Native packager within a bundle that's been loaded with ?platform=<platform>, it will resolve to ./foobar.<platform>.js or ./foobar.js. Having both foobar.ios.js and foobar.android.js being importable as ./foobar is quite powerful. Because you can push platform-dependent differences into their own modules/React components and the code that's common to both platforms simply imports the module/component while being oblivious to which platform it's actually running on.

As far as I know, webpack does not support serving multiple configurations (i.e. both Android and iOS) in the same process, so we'll need to run two webpack instances to have different module resolution rules for each platform.

balthazar commented 8 years ago

@elliottsj Any updates on this? It seems pretty important to me!

balthazar commented 8 years ago

Didn't catch #143, my bad.

philikon commented 8 years ago

As far as I know, webpack does not support serving multiple configurations (i.e. both Android and iOS) in the same process,

Fortunately that's not true! Webpack's multicompiler feature makes this easily possible. Here's how I have solved this for myself: https://github.com/mjohnston/react-native-webpack-server/pull/156#issuecomment-195826035