How to make react available on the whole app without importing it again and again in every jsx file using webpack
Asked
Active
Viewed 605 times
4
-
Take a look at [this](http://stackoverflow.com/questions/32553491/react-is-expected-to-be-globally-available/32556581#32556581). – Sal Rahman Nov 04 '16 at 21:50
1 Answers
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?

Community
- 1
- 1

Balázs Édes
- 13,452
- 6
- 54
- 89