Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use dynamic-cdn-webpack-plugin for react and react-dom #3914

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/react-scripts/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const autoprefixer = require('autoprefixer');
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const DynamicCdnWebpackPlugin = require('dynamic-cdn-webpack-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const ManifestPlugin = require('webpack-manifest-plugin');
Expand Down Expand Up @@ -376,6 +377,11 @@ module.exports = {
minifyURLs: true,
},
}),
new DynamicCdnWebpackPlugin({
only: ['react', 'react-dom'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it work when the app is cached using service worker and the network is offline? IMO this needs to be opt-in if we want to move forward with it

Copy link
Contributor Author

@swyxio swyxio Jan 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a decision the maintainers should take. we already discussed the key motivations in #2758. @gaearon and others are in favor of using CDNs in general, but I understand your concern.

as far as SW and CRA are concerned I know we are moving towards making them opt-in: #2554. its an easier call there because its just commenting out one line of code. but still. we're moving away from it for now.

IMO CRA should cater to the 90% use case as we always have eject as an option. thats what its for. as far as i understand it, service workers are not in the 90% use case for CRA (this is why we keep getting so many issues about it)

as a last resort: if we really want to we can check for something like process.env.CDNModules to opt out of it for build.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea but if people chose to opt-in for SW, it broke their expectation because the created app is no longer working offline.. I think it should be a choice between cdn capable vs offline capable. Or maybe we can configure sw-precache to cache the files from cdn?

disable: false, // switch to true to disable
verbose: false, // switch to true to log which modules are being served from CDN
}),
// Makes some environment variables available to the JS code, for example:
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
// It is absolutely essential that NODE_ENV was set to production here.
Expand Down
2 changes: 2 additions & 0 deletions packages/react-scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"css-loader": "0.28.9",
"dotenv": "4.0.0",
"dotenv-expand": "4.0.1",
"dynamic-cdn-webpack-plugin": "^3.4.1",
"eslint": "4.15.0",
"eslint-config-react-app": "^2.1.0",
"eslint-loader": "1.9.0",
Expand All @@ -47,6 +48,7 @@
"html-webpack-plugin": "2.30.1",
"identity-obj-proxy": "3.0.0",
"jest": "22.1.2",
"module-to-cdn": "^3.1.1",
"object-assign": "4.1.1",
"postcss-flexbugs-fixes": "3.2.0",
"postcss-loader": "2.0.10",
Expand Down