In my webpack build, I would like to load React from a CDN, but not ReactDOM, as it requires an extra roundtrip for a very small file.
My webpack configuration has the following block of code declaring "externals" so that it will not build these files (I instead include CDNs).
webpack.config.js
...
externals: {
react: 'React'
},
...
The problem is that only including React in externals still builds React because ReactDOM depends on it.
node_modules/react-dom/index.js
module.exports = require('react/lib/ReactDOM');
Adding 'react-dom': 'ReactDOM' to externals effectively removes them both from the bundle, but I don't want to have to include the ReactDOM CDN...
How can I configure webpack to load React from a CDN, but include ReactDOM in my main bundle?
Note: I'm using webpack 2.1.0-beta17 and React 15.1.0.
Update
I tried adding react/lib/ReactDOM to externals.
...
externals: {
react: 'React',
'react/lib/ReactDOM': 'commonjs react-dom'
},
...
But I get the following error.
require is not defined
react-domas it's own Webpack entry and make it a separate chunk? - AlexandruBreact-domas a separate chunk would not satisfy my intention to include it as part of my main bundle. - Himmel