Skip to content

Commit

Permalink
refactor: remove centralized globals for define/provide plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
pmmmwh committed May 29, 2020
1 parent 24e91ef commit 3d30d31
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
};
}

Expand Down
3 changes: 1 addition & 2 deletions src/loader/index.js
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions src/runtime/globals.js

This file was deleted.

0 comments on commit 3d30d31

Please sign in to comment.