title: What is the proper way of add babel core-js conditionally
body: <p>I was checking my site with google page speed insight and it showed &quot;Avoid serving legacy JavaScript to modern browsers&quot;</p>
  <p>I have babel-env set up something like this, which seems not working properly.</p>
  <pre><code> [&quot;@babel/preset-env&quot;, {
    &quot;useBuiltIns&quot;: &quot;usage&quot;,
    &quot;corejs&quot;: 3,
    &quot;targets&quot;: {
      &quot;browsers&quot;: [&quot;last 2 version&quot;, &quot;ie &gt; 11&quot;]
    }
  }]
  </code></pre>
  <p>On my entry.js file, I used to have import &quot;core-js/stable&quot;
  However, I tried to change like this. I am not sure core-js will actually get added before legacy browser crashes.</p>
  <pre><code>if(!isModernBrowser(navigator.userAgent)) {
    import('core-js/stable')
  }
  </code></pre>
  <p>How do you guys add core-js only for some browsers that need core-js?
  I am using a custom webpack and SSR</p>
  <p><strong>My full babelrc</strong></p>
  <pre><code>{
    &quot;presets&quot;: [
      &quot;@babel/preset-react&quot;,
      [&quot;@babel/preset-env&quot;, {
        &quot;useBuiltIns&quot;: &quot;usage&quot;,
        &quot;corejs&quot;: 3,
        &quot;targets&quot;: {
          &quot;browsers&quot;: [&quot;last 2 version&quot;, &quot;ie &gt; 11&quot;]
        }
      }]
    ],
    &quot;plugins&quot;: [
      &quot;react-hot-loader/babel&quot;,
      &quot;@babel/plugin-transform-arrow-functions&quot;,
      &quot;@babel/plugin-transform-spread&quot;,
      &quot;@babel/plugin-proposal-object-rest-spread&quot;,
      &quot;@babel/plugin-syntax-dynamic-import&quot;,
      [
        &quot;babel-plugin-webpack-alias&quot;,
        {
          &quot;config&quot;: &quot;${PWD}/config/aliases/aliases.config.js&quot;
        }
      ],
      [
        &quot;@babel/plugin-proposal-decorators&quot;,
        {
          &quot;legacy&quot;: true
        }
      ],
      &quot;@babel/plugin-transform-runtime&quot;,
      &quot;react-imported-component/babel&quot;,
      &quot;@babel/plugin-syntax-import-meta&quot;,
      &quot;@babel/plugin-proposal-class-properties&quot;,
      &quot;@babel/plugin-proposal-json-strings&quot;,
      &quot;@babel/plugin-proposal-function-sent&quot;,
      &quot;@babel/plugin-proposal-export-namespace-from&quot;,
      &quot;@babel/plugin-proposal-numeric-separator&quot;,
      &quot;@babel/plugin-proposal-throw-expressions&quot;
    ]
  }
  </code></pre>