Skip to content
Merged
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
11 changes: 7 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
};

Expand Down
5 changes: 3 additions & 2 deletions src/options.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import path from 'node:path';
import type { RuleSetCondition } from '@rspack/core';
import type { IntegrationType } from './utils/getSocketIntegration';

Expand Down Expand Up @@ -107,8 +108,8 @@ const d = <K extends keyof PluginOptions>(

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) {
Expand Down
13 changes: 10 additions & 3 deletions src/paths.ts
Original file line number Diff line number Diff line change
@@ -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],
Expand Down
12 changes: 10 additions & 2 deletions src/utils/getSocketIntegration.ts
Original file line number Diff line number Diff line change
@@ -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: {
Expand Down