Skip to content

Commit 325f610

Browse files
authored
perf: reuse resolved reactRefreshEntryPath (#10)
1 parent 5b34bc0 commit 325f610

File tree

3 files changed

+21
-18
lines changed

3 files changed

+21
-18
lines changed

src/index.ts

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'node:path';
22
import { normalizeOptions } from './options';
3+
import { reactRefreshPath, refreshUtilsPath, runtimePaths } from './paths';
34
import { getAdditionalEntries } from './utils/getAdditionalEntries';
45
import { getSocketIntegration } from './utils/getSocketIntegration';
56

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

910
export type { PluginOptions };
1011

11-
const reactRefreshPath = require.resolve('../client/reactRefresh.js');
12-
const reactRefreshEntryPath = require.resolve('../client/reactRefreshEntry.js');
13-
14-
const refreshUtilsPath = require.resolve('../client/refreshUtils.js');
15-
const refreshRuntimeDirPath = path.dirname(
16-
require.resolve('react-refresh', {
17-
paths: [reactRefreshPath],
18-
}),
19-
);
20-
21-
const runtimePaths = [
22-
reactRefreshEntryPath,
23-
reactRefreshPath,
24-
refreshUtilsPath,
25-
refreshRuntimeDirPath,
26-
];
27-
2812
class ReactRefreshRspackPlugin {
2913
options: NormalizedPluginOptions;
3014

src/paths.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import path from 'node:path';
2+
3+
export const reactRefreshPath = require.resolve('../client/reactRefresh.js');
4+
export const reactRefreshEntryPath = require.resolve(
5+
'../client/reactRefreshEntry.js',
6+
);
7+
export const refreshUtilsPath = require.resolve('../client/refreshUtils.js');
8+
export const refreshRuntimeDirPath = path.dirname(
9+
require.resolve('react-refresh', {
10+
paths: [reactRefreshPath],
11+
}),
12+
);
13+
export const runtimePaths = [
14+
reactRefreshEntryPath,
15+
reactRefreshPath,
16+
refreshUtilsPath,
17+
refreshRuntimeDirPath,
18+
];

src/utils/getAdditionalEntries.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import querystring from 'node:querystring';
22
import type { NormalizedPluginOptions } from '../options';
3+
import { reactRefreshEntryPath } from '../paths';
34

45
export interface AdditionalEntries {
56
prependEntries: string[];
@@ -86,7 +87,7 @@ export function getAdditionalEntries({
8687

8788
const prependEntries = [
8889
// React-refresh runtime
89-
require.resolve('../../client/reactRefreshEntry'),
90+
reactRefreshEntryPath,
9091
];
9192

9293
const overlayEntries = [

0 commit comments

Comments
 (0)