title: Rollup with React vendor splitting
body: <p>I'm experimenting with using Rollup as a React toolset. I've got a working prototype when I can use lazy loading in react. I'm just working with just ES6 Modules, I'll integrate SystemJS for older browsers later. My question is regarding the rollup setup. It seems crazy to treat <code>react</code> and <code>react-dom</code> as internal, then have to supply a <code>manualChunk</code> and split them out again.</p>
  
  <p>If I treat them as external and not chunk them I get the following error:</p>
  
  <pre><code>Uncaught (in promise) TypeError: Failed to resolve module specifier "react-dom". Relative references must start with either "/", "./", or "../".
  </code></pre>
  
  <p>Is there any way to treat <code>react</code> and <code>react-dom</code> as external and reference them from a CDN?</p>
  
  <pre><code>import commonjs from 'rollup-plugin-commonjs';
  import nodeResolve from 'rollup-plugin-node-resolve';
  import babel from 'rollup-plugin-babel';
  import json from 'rollup-plugin-json';
  import replace from "rollup-plugin-replace";
  
  export default {
      input: ['src/index.js'],
      output: {
          format: 'esm',
          dir: 'build',
      },
  
      experimentalCodeSplitting: true,
  
      // Is there any way to avoid this?
      manualChunks: {
          'react': ['./node_modules/react/index.js'],
          'reactDOM': ['./node_modules/react-dom/index.js'],
      },
      plugins: [
          json(),
          commonjs({
              include: 'node_modules/**',
              sourceMap: false,
              namedExports: {
                  './node_modules/react/index.js': ['Component','Children','PropTypes','createElement','cloneElement', 'createFactory'],
                  './node_modules/react-dom/index.js': ['render'],
              },
          }),
          nodeResolve(),
          babel({
              exclude: 'node_modules/**',
          }),
          replace({
              'process.env.NODE_ENV': JSON.stringify('development'),
          })
      ],
      // If react is treated as external, how can it be loaded into this ESM module from a UMD?
      // e.g. "https://unpkg.com/react@16/umd/react.development.js"
      // external: ['react','react-dom'],
  };
  </code></pre>
  
  <p>Here's the react component setup, <code>moduleA.js</code> is lazy loaded on click:</p>
  
  <pre><code>// src/moduleA.js
  const moduleA = 'Hello';
  export default { moduleA };
  
  // src/App.js
  import React, { Component } from 'react';
  import { version } from '../package.json';
  
  export default class App extends Component {
      constructor(props) {
          super(props);
          this.state = {
          };
          this.handleClick = this.handleClick.bind(this);
      }
  
      handleClick() {
          import('./moduleA')
              .then((module) =&gt; {
                  console.log(module.default);
              })
              .catch(err =&gt; {
                  // Handle failure
              });
      };
  
      render() {
          return (
              &lt;React.Fragment&gt;
                  &lt;div className="App"&gt;
                      &lt;h1&gt;Hello, World!&lt;/h1&gt;
                      &lt;p&gt;This is version: { version }&lt;/p&gt;
                  &lt;/div&gt;
                  &lt;button onClick={this.handleClick}&gt;Load&lt;/button&gt;
              &lt;/React.Fragment&gt;
          );
      }
  }
  
  // src/index.js
  import React from 'react';
  import ReactDOM from 'react-dom';
  import App from './App';
  
  ReactDOM.render(&lt;App /&gt;, document.getElementById('root'));
  
  
  //html
  &lt;!doctype html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta charset="UTF-8"&gt;
  &lt;title&gt;#&lt;/title&gt;
  &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;main id="root"&gt;&lt;/main&gt;
  &lt;!-- How can these be referenced in the below module?
      &lt;script crossorigin src="https://unpkg.com/react@16/umd/react.development.js"&gt;&lt;/script&gt;
      &lt;script crossorigin src="https://unpkg.com/react-dom@16/umd/react-dom.development.js"&gt;&lt;/script&gt;
  --&gt;
      &lt;script type="module"&gt;
          import('/index.js');
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>