Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CDN vs Webpack for React

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!

like image 735
idude Avatar asked Jul 27 '17 19:07

idude


People also ask

Should you use a CDN with React?

You need ReactJS CDN to load your React and Components into the ReactJs ecosystem. You need ReactDOM to render your Components in the DOM Tree, and you need Babel to transpile your JSX to simple JS so that all the browsers can read them.

Is webpack necessary for React?

Well, we don't necessarily need webpack to work with React, other alternatives could be Browserify, Parsel, Brunch, etc, but honestly, I don't know how well they fit in with React. js. Webpack is the most widely used and an accepted module bundler and task runner throughout React. js community.

Why use webpack instead of create React app?

Configuring webpack provides complete control over the development environment, while initializing with Create React App prevents any custom configuration by default.

What is CDN for React?

As is the case with content delivery networks, a React CDN combination reduces the distance between the server and the user to accelerate the delivery of library assets so that webpages would load faster.


1 Answers

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

This was made for this use case.

like image 65
Kev Avatar answered Sep 27 '22 19:09

Kev