facebookarchive / react-360

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

Using a CDN to serve bundled files (client.bundle.js and index.bundle.js) #279

Closed amitrajput1992 closed 7 years ago

amitrajput1992 commented 7 years ago

Description

Is there a way to serve up the bundled files from a different server than where the application runs?

For ex. after bundling both client.js and index.js I want to serve these files from http://cdn.exp.com/*** to (take advantage of caching and other stuff) rather than to have these in the website directory. I see that inside VRInstance.js, the bundle(index.js) is always referenced from the working directory inside bundleFromRoot function. Though client.js bundle can be requested from external server. Since both of these are standalone bundles after building, it would be ideal that these can be referenced from any location, be it inside the app directory or on a different server.

I can set up a PR to address this issue if this wasn't on the roadmap for react-vr.

Expected behavior

Serving bundled files from a different source.

Actual behavior

VRInstance references bundled files always from the root directory.

Solution

Add additional param for VRInstance options {bundleFromRoot: true/false} and corresponding test for this while referencing the bundles.

ReactVR.init(
    // When you're ready to deploy your app, update this line to point to
    // your compiled index.bundle.js
    'vr/index.vr.bundle?platform=vr&dev=true&enableHotReload=true',
    // Attach it to the body tag
    document.body,
    {
        bundleFromRoot: false 
    }
  );

this.rootView = createRootView(this.guiSys, root, {
      // Name of the mounted root module, from AppRegistry
      assetRoot: assetRoot,
      bundle: !options.bundleFromRoot? bundle: bundleFromRoot(bundle),
      customViews: options.customViews,
      enableHotReload: options.enableHotReload,
      initialProps: options.initialProps,
      isLowLatency: !this.player.isMobile,
      nativeModules: options.nativeModules,
    });

Additional Information

mikearmstrong001 commented 7 years ago

So in short you want to be able to specify the absolute url. Rather than add another option perhaps detecting this in a renamed bundleFromRoot would be a better solution. PR would be much appreciated :)

amitrajput1992 commented 7 years ago

I will setup a PR soon

amitrajput1992 commented 7 years ago

sent #281 for this issue. @mikearmstrong001, please review.

mikearmstrong001 commented 7 years ago

Many thanks I'll take a look

mikearmstrong001 commented 7 years ago

closing and moving discussion to PR

hitu4233 commented 4 years ago

Where we can get path of bundle.js and main.bundle.js in our local how we can put these on CDN and serve to our application?