@vitejs/plugin-react 4.4.0-beta.1 → 4.4.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -0
- package/dist/index.cjs +4 -3
- package/dist/index.d.cts +8 -0
- package/dist/index.d.mts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.mjs +4 -3
- package/package.json +3 -3
package/README.md
CHANGED
@@ -94,6 +94,16 @@ This option does not enable _code transformation_. That is handled by esbuild.
|
|
94
94
|
|
95
95
|
Here's the [complete list of Babel parser plugins](https://babeljs.io/docs/en/babel-parser#ecmascript-proposalshttpsgithubcombabelproposals).
|
96
96
|
|
97
|
+
### reactRefreshHost
|
98
|
+
|
99
|
+
The `reactRefreshHost` option is only necessary in a module federation context. It enables HMR to work between a remote & host application. In your remote Vite config, you would add your host origin:
|
100
|
+
|
101
|
+
```js
|
102
|
+
react({ reactRefreshHost: 'http://localhost:3000' })
|
103
|
+
```
|
104
|
+
|
105
|
+
Under the hood, this simply updates the React Fash Refresh runtime URL from `/@react-refresh` to `http://localhost:3000/@react-refresh` to ensure there is only one Refresh runtime across the whole application. Note that if you define `base` option in the host application, you need to include it in the option, like: `http://localhost:3000/{base}`.
|
106
|
+
|
97
107
|
## Middleware mode
|
98
108
|
|
99
109
|
In [middleware mode](https://vite.dev/config/server-options.html#server-middlewaremode), you should make sure your entry `index.html` file is transformed by Vite. Here's an example for an Express server:
|
package/dist/index.cjs
CHANGED
@@ -17,7 +17,7 @@ window.$RefreshReg$ = () => {};
|
|
17
17
|
window.$RefreshSig$ = () => (type) => type;`;
|
18
18
|
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
19
19
|
const avoidSourceMapOption = Symbol();
|
20
|
-
function addRefreshWrapper(code, map, pluginName, id) {
|
20
|
+
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
21
21
|
const hasRefresh = refreshContentRE.test(code);
|
22
22
|
const onlyReactComp = !hasRefresh && reactCompRE.test(code);
|
23
23
|
const normalizedMap = map === avoidSourceMapOption ? null : map;
|
@@ -58,7 +58,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
58
58
|
}
|
59
59
|
}
|
60
60
|
const sharedHead = removeLineBreaksIfNeeded(
|
61
|
-
`import * as RefreshRuntime from "${runtimePublicPath}";
|
61
|
+
`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
62
62
|
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
63
63
|
|
64
64
|
`,
|
@@ -241,7 +241,8 @@ function viteReact(opts = {}) {
|
|
241
241
|
result.code,
|
242
242
|
result.map,
|
243
243
|
"@vitejs/plugin-react",
|
244
|
-
id
|
244
|
+
id,
|
245
|
+
opts.reactRefreshHost
|
245
246
|
);
|
246
247
|
}
|
247
248
|
}
|
package/dist/index.d.cts
CHANGED
@@ -21,6 +21,14 @@ interface Options {
|
|
21
21
|
babel?: BabelOptions | ((id: string, options: {
|
22
22
|
ssr?: boolean;
|
23
23
|
}) => BabelOptions);
|
24
|
+
/**
|
25
|
+
* React Fast Refresh runtime URL prefix.
|
26
|
+
* Useful in a module federation context to enable HMR by specifying
|
27
|
+
* the host application URL in the Vite config of a remote application.
|
28
|
+
* @example
|
29
|
+
* reactRefreshHost: 'http://localhost:3000'
|
30
|
+
*/
|
31
|
+
reactRefreshHost?: string;
|
24
32
|
}
|
25
33
|
type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
26
34
|
/**
|
package/dist/index.d.mts
CHANGED
@@ -21,6 +21,14 @@ interface Options {
|
|
21
21
|
babel?: BabelOptions | ((id: string, options: {
|
22
22
|
ssr?: boolean;
|
23
23
|
}) => BabelOptions);
|
24
|
+
/**
|
25
|
+
* React Fast Refresh runtime URL prefix.
|
26
|
+
* Useful in a module federation context to enable HMR by specifying
|
27
|
+
* the host application URL in the Vite config of a remote application.
|
28
|
+
* @example
|
29
|
+
* reactRefreshHost: 'http://localhost:3000'
|
30
|
+
*/
|
31
|
+
reactRefreshHost?: string;
|
24
32
|
}
|
25
33
|
type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
26
34
|
/**
|
package/dist/index.d.ts
CHANGED
@@ -21,6 +21,14 @@ interface Options {
|
|
21
21
|
babel?: BabelOptions | ((id: string, options: {
|
22
22
|
ssr?: boolean;
|
23
23
|
}) => BabelOptions);
|
24
|
+
/**
|
25
|
+
* React Fast Refresh runtime URL prefix.
|
26
|
+
* Useful in a module federation context to enable HMR by specifying
|
27
|
+
* the host application URL in the Vite config of a remote application.
|
28
|
+
* @example
|
29
|
+
* reactRefreshHost: 'http://localhost:3000'
|
30
|
+
*/
|
31
|
+
reactRefreshHost?: string;
|
24
32
|
}
|
25
33
|
type BabelOptions = Omit<TransformOptions, 'ast' | 'filename' | 'root' | 'sourceFileName' | 'sourceMaps' | 'inputSourceMap'>;
|
26
34
|
/**
|
package/dist/index.mjs
CHANGED
@@ -14,7 +14,7 @@ window.$RefreshReg$ = () => {};
|
|
14
14
|
window.$RefreshSig$ = () => (type) => type;`;
|
15
15
|
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
16
16
|
const avoidSourceMapOption = Symbol();
|
17
|
-
function addRefreshWrapper(code, map, pluginName, id) {
|
17
|
+
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
18
18
|
const hasRefresh = refreshContentRE.test(code);
|
19
19
|
const onlyReactComp = !hasRefresh && reactCompRE.test(code);
|
20
20
|
const normalizedMap = map === avoidSourceMapOption ? null : map;
|
@@ -55,7 +55,7 @@ if (import.meta.hot && !inWebWorker) {
|
|
55
55
|
}
|
56
56
|
}
|
57
57
|
const sharedHead = removeLineBreaksIfNeeded(
|
58
|
-
`import * as RefreshRuntime from "${runtimePublicPath}";
|
58
|
+
`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
59
59
|
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
60
60
|
|
61
61
|
`,
|
@@ -238,7 +238,8 @@ function viteReact(opts = {}) {
|
|
238
238
|
result.code,
|
239
239
|
result.map,
|
240
240
|
"@vitejs/plugin-react",
|
241
|
-
id
|
241
|
+
id,
|
242
|
+
opts.reactRefreshHost
|
242
243
|
);
|
243
244
|
}
|
244
245
|
}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@vitejs/plugin-react",
|
3
|
-
"version": "4.4.0-beta.
|
3
|
+
"version": "4.4.0-beta.2",
|
4
4
|
"license": "MIT",
|
5
5
|
"author": "Evan You",
|
6
6
|
"description": "The default Vite plugin for React projects",
|
@@ -48,11 +48,11 @@
|
|
48
48
|
},
|
49
49
|
"homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react#readme",
|
50
50
|
"dependencies": {
|
51
|
-
"@babel/core": "^7.26.
|
51
|
+
"@babel/core": "^7.26.10",
|
52
52
|
"@babel/plugin-transform-react-jsx-self": "^7.25.9",
|
53
53
|
"@babel/plugin-transform-react-jsx-source": "^7.25.9",
|
54
54
|
"@types/babel__core": "^7.20.5",
|
55
|
-
"react-refresh": "^0.
|
55
|
+
"react-refresh": "^0.17.0"
|
56
56
|
},
|
57
57
|
"peerDependencies": {
|
58
58
|
"vite": "^4.2.0 || ^5.0.0 || ^6.0.0"
|