facebookarchive / react-360

Create amazing 360 and VR content using React
https://facebook.github.io/react-360
Other
8.73k stars 1.22k forks source link

Is there any way to deliver some variables to React 360 when it starts? #502

Open zzc-tongji opened 6 years ago

zzc-tongji commented 6 years ago

How to get WEBVR_ENV when I use WEBVR_ENV=test node node_modules/react-native/local-cli/cli.js start to run the project?

I have tried to use process.env.WEBVR_ENV, but it is undefined. console.log(process.env.WEBVR_ENV) shows {NODE_ENV: "development"}.

andrewimm commented 6 years ago

This functionality is handled by the React Native Bundler (Metro) and out of the scope of React 360.

How are you using this environment variable? If you're toggling behavior, it might be easier to pass a variable at initialization time. If you're hoping to completely eliminate some code in production, the React Native bundler isn't set up to do full dead code elimination. It does handle one case, __DEV__, which is true in development builds and false in release builds. The bundler will completely eliminate statements like if (__DEV__) in release builds. This may be what you're looking for.

dikshantpatodia commented 5 years ago

Didn't get how to pass the config variables to worker thread in react 360.

zzc-tongji commented 5 years ago

I got it.

There is no way to parse any environment variables to index.vr.js, since index.vr.js is running in a "visual machine" (independent space, more exactly) in browser.

One solution (perhaps not so good) is to create a file environment.js and import it to index.vr.js. Change it before running or bundling to parse something outside.