Skip to content

Commit 5a94bd7

Browse files
authored
feat: add filter (#470)
1 parent fc9302b commit 5a94bd7

File tree

10 files changed

+206
-126
lines changed

10 files changed

+206
-126
lines changed

packages/plugin-react-oxc/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Add `filter` for rolldown-vite
6+
7+
Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.
8+
59
## 0.1.1 (2025-04-10)
610

711
## 0.1.0 (2025-04-09)

packages/plugin-react-oxc/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,8 @@
4646
"@vitejs/react-common": "workspace:*",
4747
"unbuild": "^3.5.0",
4848
"vite": "catalog:rolldown-vite"
49+
},
50+
"dependencies": {
51+
"@rolldown/pluginutils": "1.0.0-beta.9"
4952
}
5053
}

packages/plugin-react-oxc/src/index.ts

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
runtimePublicPath,
1010
silenceUseClientWarning,
1111
} from '@vitejs/react-common'
12+
import { exactRegex } from '@rolldown/pluginutils'
1213

1314
const _dirname = dirname(fileURLToPath(import.meta.url))
1415

@@ -149,12 +150,3 @@ export default function viteReact(opts: Options = {}): PluginOption[] {
149150

150151
return [viteConfig, viteRefreshRuntime, viteRefreshWrapper]
151152
}
152-
153-
function exactRegex(input: string): RegExp {
154-
return new RegExp(`^${escapeRegex(input)}$`)
155-
}
156-
157-
const escapeRegexRE = /[-/\\^$*+?.()|[\]{}]/g
158-
function escapeRegex(str: string): string {
159-
return str.replace(escapeRegexRE, '\\$&')
160-
}

packages/plugin-react-swc/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Add `filter` for rolldown-vite
6+
7+
Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.
8+
59
### Skip HMR preamble in Vitest browser mode
610

711
This was causing annoying `Sourcemap for "/@react-refresh" points to missing source files` and is unnecessary in test mode.

packages/plugin-react-swc/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc#readme",
3131
"dependencies": {
32+
"@rolldown/pluginutils": "1.0.0-beta.9",
3233
"@swc/core": "^1.11.22"
3334
},
3435
"peerDependencies": {

packages/plugin-react-swc/src/index.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
runtimePublicPath,
1919
silenceUseClientWarning,
2020
} from '@vitejs/react-common'
21+
import { exactRegex } from '@rolldown/pluginutils'
2122

2223
/* eslint-disable no-restricted-globals */
2324
const _dirname =
@@ -96,14 +97,23 @@ const react = (_options?: Options): PluginOption[] => {
9697
name: 'vite:react-swc:resolve-runtime',
9798
apply: 'serve',
9899
enforce: 'pre', // Run before Vite default resolve to avoid syscalls
99-
resolveId: (id) => (id === runtimePublicPath ? id : undefined),
100-
load: (id) =>
101-
id === runtimePublicPath
102-
? readFileSync(join(_dirname, 'refresh-runtime.js'), 'utf-8').replace(
103-
/__README_URL__/g,
104-
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc',
105-
)
106-
: undefined,
100+
resolveId: {
101+
filter: { id: exactRegex(runtimePublicPath) },
102+
handler: (id) => (id === runtimePublicPath ? id : undefined),
103+
},
104+
load: {
105+
filter: { id: exactRegex(runtimePublicPath) },
106+
handler: (id) =>
107+
id === runtimePublicPath
108+
? readFileSync(
109+
join(_dirname, 'refresh-runtime.js'),
110+
'utf-8',
111+
).replace(
112+
/__README_URL__/g,
113+
'https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc',
114+
)
115+
: undefined,
116+
},
107117
},
108118
{
109119
name: 'vite:react-swc',

packages/plugin-react/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Add `filter` for rolldown-vite
6+
7+
Added `filter` so that it is more performant when running this plugin with rolldown-powered version of Vite.
8+
59
## 4.4.1 (2025-04-19)
610

711
Fix type issue when using `moduleResolution: "node"` in tsconfig [#462](https://github.com/vitejs/vite-plugin-react/pull/462)

packages/plugin-react/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
"@babel/core": "^7.26.10",
5252
"@babel/plugin-transform-react-jsx-self": "^7.25.9",
5353
"@babel/plugin-transform-react-jsx-source": "^7.25.9",
54+
"@rolldown/pluginutils": "1.0.0-beta.9",
5455
"@types/babel__core": "^7.20.5",
5556
"react-refresh": "^0.17.0"
5657
},

0 commit comments

Comments
 (0)