reactjswebpackwebpack-3

Webpack externals doesn't seem to work for nested objects.


I was using my webpack externals like this and it works fine.

externals: {
    react: {
       root: React
    }
  }

But now I am injecting the webpack script for a child window , so instead of Window , React is now available in window.parent. So basically any calls to import React should fallback to window.parent.React

How do i do this using externals ? I have tried like this

externals: {
    react: {
       root: ["parent", "React"]
    }
  }

But it doesn't work. What am I missing ?


Solution

  • Finally found the answer to this

    externals: {
      react: "parent.React"
    }
    

    is the correct way