title: How to optimize React app bundle size using rollup.js
body: <p>I am trying to use rollup.js to bundle my react app. And i realized the bundle .js file is bigger than compiled with create-react-app.
  How can I solve this. I just discovered rollup.js last two weeks and love it. I need help to get this done.</p>
  
  <p>I tried with options I found on the net by creating peerDev in package.json like below </p>
  
  <pre><code>"peerDependencies": {
      "react": "&gt;= 16.x.x",
      "styled-jsx": "&gt;= 3.x.x"
    } 
  </code></pre>
  
  <p>and then with this line "external: id => /^react|styled-jsx/.test(id)," in rollup.config.js. I realized this has to do with react components only but not bundling for react app even though it did reduce the file size drastically. The page doesn't run when compiled that way</p>
  
  <p>This is the rollup config file without the peerDependencies reference</p>
  
  <pre><code>import resolve from "rollup-plugin-node-resolve";
  import commonjs from "rollup-plugin-commonjs";
  import livereload from "rollup-plugin-livereload";
  import { terser } from "rollup-plugin-terser";
  import replace from "rollup-plugin-replace";
  //import pkg from "./package.json";
  
  const production = !process.env.ROLLUP_WATCH;
  const NODE_ENV = process.env.NODE_ENV;
  
  export default [
    {
      input: "src/index.js",
      output: {
        name: "bundle",
        file: "dist/main.js",
        format: "iife"
      },
      "process.env": {
        NODE_ENV: JSON.stringify("production")
      },
      plugins: [
        replace({
        "process.env.NODE_ENV": JSON.stringify(NODE_ENV)
      }),
      babel({
        exclude: "node_modules/**"
      }),
      resolve(),
      commonjs(),
        !production &amp;&amp; livereload("dist"),
        production &amp;&amp; terser()
      ],
      globals: {
        react: "React"
      },
      watch: {
        clearScreen: false
      }
    }
  ];
  </code></pre>
  
  <p>And this is just the simple react code.</p>
  
  <pre><code>import ReactDOM from 'react-dom';
  
  ReactDOM.render(&lt;h3&gt;React with Rollup&lt;/h3&gt;,document.getElementById('root'));
  </code></pre>
  
  <p>After compilation. This is the file size I get 961K. This should be smaller. Becuase, with much bigger applications, the file sizes are far smaller than this. Prompt help will be very much appreciated</p>