score:3

Using the ProvidePlugin. Docs: https://webpack.github.io/docs/shimming-modules.html

But just so we have code here, add this to plugins:

new webpack.ProvidePlugin({
  React: "react",
})

This essentially does a require('react') and makes the result a global variable called React, which is accessible for all modules.

See more options in this answer: Webpack ProvidePlugin vs externals?


Related Query

More Query from same tag