Reputation: 8968
Using webpack is it possible to include ReactJS as a separate library?
For example, in webpack.config.js
I add the following to ensure react
and react-dom
are not bundled with the application:
externals: {
"react": "React",
"react-dom": "ReactDOM"
},
But, I need the react library available before deployment. Is it possible for webpack to copy, or include, the react library as a separate file?
Upvotes: 1
Views: 2759
Reputation: 2053
You can tell webpack to use multiple entry points. So one entry point would be your application and the other the react library. When you combine this with the webpack html plugin, all these dependencies are automatically added to your html file. Please check the order of the entry points, because the react library must be included before your application.
For further reading see this example: https://github.com/webpack/webpack/tree/master/examples/multi-part-library
Upvotes: 2