From 3d30d311887b398e5c3b3423763d9556efe089f7 Mon Sep 17 00:00:00 2001 From: Michael Mok Date: Fri, 29 May 2020 16:44:53 +0800 Subject: [PATCH] refactor: remove centralized globals for define/provide plugin --- src/index.js | 9 ++++----- src/loader/index.js | 3 +-- src/runtime/globals.js | 5 ----- 3 files changed, 5 insertions(+), 12 deletions(-) delete mode 100644 src/runtime/globals.js diff --git a/src/index.js b/src/index.js index 744d79d0..8a98eedb 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,6 @@ const ConstDependency = require('webpack/lib/dependencies/ConstDependency'); const NullFactory = require('webpack/lib/NullFactory'); const ParserHelpers = require('webpack/lib/ParserHelpers'); const { getSocketIntegration, injectRefreshEntry, normalizeOptions } = require('./helpers'); -const { errorOverlay, initSocket, refreshUtils } = require('./runtime/globals'); const schema = require('./options.json'); // Mapping of react-refresh globals to Webpack require extensions @@ -64,18 +63,18 @@ class ReactRefreshPlugin { // Inject necessary modules to bundle's global scope let providedModules = { - [refreshUtils]: require.resolve('./runtime/refreshUtils'), + __react_refresh_utils__: require.resolve('./runtime/refreshUtils'), }; if (this.options.overlay === false) { // Stub errorOverlay module so calls to it will be erased - const definePlugin = new DefinePlugin({ [errorOverlay]: false }); + const definePlugin = new DefinePlugin({ __react_refresh_error_overlay__: false }); definePlugin.apply(compiler); } else { providedModules = { ...providedModules, - [errorOverlay]: require.resolve(this.options.overlay.module), - [initSocket]: getSocketIntegration(this.options.overlay.sockIntegration), + __react_refresh_error_overlay__: require.resolve(this.options.overlay.module), + __react_refresh_init_socket__: getSocketIntegration(this.options.overlay.sockIntegration), }; } diff --git a/src/loader/index.js b/src/loader/index.js index 3ae02f3f..0f8d2110 100644 --- a/src/loader/index.js +++ b/src/loader/index.js @@ -1,6 +1,5 @@ const { SourceMapConsumer, SourceNode } = require('source-map'); const { Template } = require('webpack'); -const { refreshUtils } = require('../runtime/globals'); const RefreshSetupRuntime = Template.getFunctionContent(require('./RefreshSetup.runtime')) .trim() @@ -9,7 +8,7 @@ const RefreshSetupRuntime = Template.getFunctionContent(require('./RefreshSetup. const RefreshModuleRuntime = Template.getFunctionContent(require('./RefreshModule.runtime')) .trim() .replace(/^ {2}/gm, '') - .replace(/\$RefreshUtils\$/g, refreshUtils); + .replace(/\$RefreshUtils\$/g, '__react_refresh_utils__'); /** * A simple Webpack loader to inject react-refresh HMR code into modules. diff --git a/src/runtime/globals.js b/src/runtime/globals.js deleted file mode 100644 index f4020c25..00000000 --- a/src/runtime/globals.js +++ /dev/null @@ -1,5 +0,0 @@ -module.exports = { - errorOverlay: '__react_refresh_error_overlay__', - initSocket: '__react_refresh_init_socket__', - refreshUtils: '__react_refresh_utils__', -};