diff --git a/src/index.ts b/src/index.ts index aebf279..8c57cfb 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,10 @@ -import path from 'node:path'; import { normalizeOptions } from './options'; -import { reactRefreshPath, refreshUtilsPath, runtimePaths } from './paths'; +import { + reactRefreshPath, + refreshRuntimeDirPath, + refreshUtilsPath, + runtimePaths, +} from './paths'; import { getAdditionalEntries } from './utils/getAdditionalEntries'; import { type IntegrationType, @@ -131,9 +135,8 @@ class ReactRefreshRspackPlugin { new compiler.webpack.DefinePlugin(definedModules).apply(compiler); new compiler.webpack.ProvidePlugin(providedModules).apply(compiler); - const refreshPath = path.dirname(require.resolve('react-refresh')); compiler.options.resolve.alias = { - 'react-refresh': refreshPath, + 'react-refresh': refreshRuntimeDirPath, ...compiler.options.resolve.alias, }; diff --git a/src/options.ts b/src/options.ts index 96fe364..2765901 100644 --- a/src/options.ts +++ b/src/options.ts @@ -1,3 +1,4 @@ +import path from 'node:path'; import type { RuleSetCondition } from '@rspack/core'; import type { IntegrationType } from './utils/getSocketIntegration'; @@ -107,8 +108,8 @@ const d = ( const normalizeOverlay = (options: PluginOptions['overlay']) => { const defaultOverlay: OverlayOptions = { - entry: require.resolve('../client/errorOverlayEntry.js'), - module: require.resolve('../client/overlay/index.js'), + entry: path.join(__dirname, '../client/errorOverlayEntry.js'), + module: path.join(__dirname, '../client/overlay/index.js'), sockIntegration: 'wds', }; if (!options) { diff --git a/src/paths.ts b/src/paths.ts index e4aed4f..3c9ebb8 100644 --- a/src/paths.ts +++ b/src/paths.ts @@ -1,10 +1,17 @@ import path from 'node:path'; -export const reactRefreshPath = require.resolve('../client/reactRefresh.js'); -export const reactRefreshEntryPath = require.resolve( +export const reactRefreshPath = path.join( + __dirname, + '../client/reactRefresh.js', +); +export const reactRefreshEntryPath = path.join( + __dirname, '../client/reactRefreshEntry.js', ); -export const refreshUtilsPath = require.resolve('../client/refreshUtils.js'); +export const refreshUtilsPath = path.join( + __dirname, + '../client/refreshUtils.js', +); export const refreshRuntimeDirPath = path.dirname( require.resolve('react-refresh', { paths: [reactRefreshPath], diff --git a/src/utils/getSocketIntegration.ts b/src/utils/getSocketIntegration.ts index a96f072..393a568 100644 --- a/src/utils/getSocketIntegration.ts +++ b/src/utils/getSocketIntegration.ts @@ -1,14 +1,22 @@ +import path from 'node:path'; + export type IntegrationType = 'wds' | 'whm' | (string & {}); export function getSocketIntegration(integrationType: IntegrationType) { let resolvedSocketIntegration: string; switch (integrationType) { case 'wds': { - resolvedSocketIntegration = require.resolve('./sockets/WDSSocket'); + resolvedSocketIntegration = path.join( + __dirname, + './sockets/WDSSocket.js', + ); break; } case 'whm': { - resolvedSocketIntegration = require.resolve('./sockets/WHMEventSource'); + resolvedSocketIntegration = path.join( + __dirname, + './sockets/WHMEventSource.js', + ); break; } default: {