From 991b092c893b916e6fd34e408e96a395d47b6008 Mon Sep 17 00:00:00 2001 From: Joe Haddad Date: Wed, 11 Oct 2017 18:16:38 -0400 Subject: [PATCH] Use production React version for bundled overlay (#3267) * Use production React version * We cannot strip our own checks if production * Keep the sourcemap during minify * Prevent devtools pollution * Add some comments * sigh --- packages/react-error-overlay/package.json | 3 +-- .../webpack.config.iframe.js | 24 ++++++++++++++++++- .../react-error-overlay/webpack.config.js | 1 - 3 files changed, 24 insertions(+), 4 deletions(-) diff --git a/packages/react-error-overlay/package.json b/packages/react-error-overlay/package.json index cb0a3193fec..9e36bf7e885 100644 --- a/packages/react-error-overlay/package.json +++ b/packages/react-error-overlay/package.json @@ -27,8 +27,7 @@ ], "author": "Joe Haddad ", "files": [ - "lib/", - "middleware.js" + "lib/index.js" ], "devDependencies": { "anser": "1.4.1", diff --git a/packages/react-error-overlay/webpack.config.iframe.js b/packages/react-error-overlay/webpack.config.iframe.js index 9fa742b720b..031762e5937 100644 --- a/packages/react-error-overlay/webpack.config.iframe.js +++ b/packages/react-error-overlay/webpack.config.iframe.js @@ -7,9 +7,9 @@ 'use strict'; const path = require('path'); +const webpack = require('webpack'); module.exports = { - devtool: 'cheap-module-source-map', entry: './src/iframeScript.js', output: { path: path.join(__dirname, './lib'), @@ -24,4 +24,26 @@ module.exports = { }, ], }, + plugins: [ + new webpack.DefinePlugin({ + // We set process.env.NODE_ENV to 'production' so that React is built + // in production mode. + 'process.env': { NODE_ENV: '"production"' }, + // This prevents our bundled React from accidentally hijacking devtools. + __REACT_DEVTOOLS_GLOBAL_HOOK__: + '__REACT_ERROR_OVERLAY_GLOBAL_HOOK_NOOP__', + }), + // This code is embedded as a string, so it would never be optimized + // elsewhere. + new webpack.optimize.UglifyJsPlugin({ + compress: { + warnings: false, + comparisons: false, + }, + output: { + comments: false, + ascii_only: false, + }, + }), + ], }; diff --git a/packages/react-error-overlay/webpack.config.js b/packages/react-error-overlay/webpack.config.js index 5d640e05ca3..bc8b363f765 100644 --- a/packages/react-error-overlay/webpack.config.js +++ b/packages/react-error-overlay/webpack.config.js @@ -9,7 +9,6 @@ const path = require('path'); module.exports = { - devtool: 'cheap-module-source-map', entry: './src/index.js', output: { path: path.join(__dirname, './lib'),