Webpack2, how to exclude react and react dom from build
<p>My goal is to create a module for a react components library made in ES6 using webpack.</p>

<p>I am using:</p>

<ul>
<li>webpack: "2.1.0-beta.25"</li>
<li>react: "15.4.1"</li>
</ul>

<p>I need to assign <code>react</code> and <code>react-dom</code> as peerDependencies so it doesn't get downloaded by the developer.</p>

<p>This is the relevant part of my <code>package.json</code>:</p>

<pre><code>"peerDependencies": {
  "react": "15.4.1"
},
"dependencies": {
  "chalk": "1.1.3",
  "compression": "1.6.2",
  "cross-env": "3.1.3",
  "immutable": "3.8.1",
  "invariant": "2.2.1",
  "lodash": "4.16.4",
  "minimist": "1.2.0",
  "sanitize.css": "4.1.0",
  "warning": "3.0.0",
  "react-onclickoutside": "5.8.3",
  "styled-components": "1.1.2",
  "classnames": "2.2.5"
},
"devDependencies": {
  "react": "15.4.1",
  "react-dom": "15.4.1",
</code></pre>

<p>According to <a href="https://webpack.github.io/docs/configuration.html#externals" rel="nofollow noreferrer">https://webpack.github.io/docs/configuration.html#externals</a> and <a href="https://webpack.github.io/docs/library-and-externals.html" rel="nofollow noreferrer">https://webpack.github.io/docs/library-and-externals.html</a>,</p>

<p>I have tried the following configuration : </p>

<p>1.</p>

<pre><code>externals: {
  react: {
    root: 'React',
    commonjs2: 'react',
    commonjs: 'react',
    amd: 'react'
  },
  'react-dom': {
    root: 'ReactDOM',
    commonjs2: 'react-dom',
    commonjs: 'react-dom',
    amd: 'react-dom'
  }
},
</code></pre>

<p>2.
    externals: {
      react: 'react',
      'react-dom' : 'react-dom',
    }</p>

<p>3.</p>

<pre><code> externals: {
  react: 'React',
  'react-dom' : 'ReactDOM',
 }
</code></pre>

<p>4.</p>

<pre><code>externals: {
  react: 'umd react',
  'react-dom' : 'umd react-dom'
}
</code></pre>

<p>5.</p>

<pre><code>    externals: {
        // Use external version of React
        "react": "React",
        "react-dom": "ReactDOM"
    },
</code></pre>

<p>I always have this error :</p>

<pre><code> Dynamic page loading failed Error: addComponentAsRefTo(...): Only a ReactOwner can have refs. You might be adding a ref to a component that was not created inside a component's `render` method, or you have multiple copies of React loaded (details: https://bf.me/react-refs-must-have-owner).(…)
</code></pre>

<p>So I wonder, the documentation isn't very clear on that.</p>

<p>In december 2017, january 2018 at maximum, how can I exclude <code>React</code> and <code>ReactDOM</code> from being bundled ?</p>