9

So I'm attempting to create my first React application, and when I compile it using webpack, I get a pretty large JS file, because it includes all React, React-DOM, etc.

Is there any way I can use one of the many React CDN's out there and still use

import React from "react";
import ReactDOM from "react-dom";

Thanks in advance!

Daniel A. White
  • 181,601
  • 45
  • 354
  • 430
idude
  • 4,404
  • 8
  • 30
  • 46
  • Possible duplicate of [How to use a library from a CDN in a Webpack project in production](https://stackoverflow.com/questions/31575809/how-to-use-a-library-from-a-cdn-in-a-webpack-project-in-production) – mastilver Jul 31 '17 at 18:14
  • I think this would actually be efficient if most web apps were actually loading react and react-dom from the CDN, so the libraries world already be in your browser for your app to use, but the promoted way is create-react-app which bundles it all – Tsortanidis Christos May 23 '18 at 22:55

1 Answers1

5

You should look at webpack externals feature: https://webpack.js.org/configuration/externals/

This was made for this use case.

Kev
  • 4,605
  • 4
  • 30
  • 50