Skip to content

Commit

Permalink
perf: reuse resolved reactRefreshEntryPath (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Nov 8, 2024
1 parent 5b34bc0 commit 325f610
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
18 changes: 1 addition & 17 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import path from 'node:path';
import { normalizeOptions } from './options';
import { reactRefreshPath, refreshUtilsPath, runtimePaths } from './paths';
import { getAdditionalEntries } from './utils/getAdditionalEntries';
import { getSocketIntegration } from './utils/getSocketIntegration';

Expand All @@ -8,23 +9,6 @@ import type { NormalizedPluginOptions, PluginOptions } from './options';

export type { PluginOptions };

const reactRefreshPath = require.resolve('../client/reactRefresh.js');
const reactRefreshEntryPath = require.resolve('../client/reactRefreshEntry.js');

const refreshUtilsPath = require.resolve('../client/refreshUtils.js');
const refreshRuntimeDirPath = path.dirname(
require.resolve('react-refresh', {
paths: [reactRefreshPath],
}),
);

const runtimePaths = [
reactRefreshEntryPath,
reactRefreshPath,
refreshUtilsPath,
refreshRuntimeDirPath,
];

class ReactRefreshRspackPlugin {
options: NormalizedPluginOptions;

Expand Down
18 changes: 18 additions & 0 deletions src/paths.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import path from 'node:path';

export const reactRefreshPath = require.resolve('../client/reactRefresh.js');
export const reactRefreshEntryPath = require.resolve(
'../client/reactRefreshEntry.js',
);
export const refreshUtilsPath = require.resolve('../client/refreshUtils.js');
export const refreshRuntimeDirPath = path.dirname(
require.resolve('react-refresh', {
paths: [reactRefreshPath],
}),
);
export const runtimePaths = [
reactRefreshEntryPath,
reactRefreshPath,
refreshUtilsPath,
refreshRuntimeDirPath,
];
3 changes: 2 additions & 1 deletion src/utils/getAdditionalEntries.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import querystring from 'node:querystring';
import type { NormalizedPluginOptions } from '../options';
import { reactRefreshEntryPath } from '../paths';

export interface AdditionalEntries {
prependEntries: string[];
Expand Down Expand Up @@ -86,7 +87,7 @@ export function getAdditionalEntries({

const prependEntries = [
// React-refresh runtime
require.resolve('../../client/reactRefreshEntry'),
reactRefreshEntryPath,
];

const overlayEntries = [
Expand Down

0 comments on commit 325f610

Please sign in to comment.