@vitejs/plugin-react-swc 3.9.0-beta.2 → 3.9.0

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 CHANGED
@@ -93,6 +93,16 @@ react({
93
93
  })
94
94
  ```
95
95
 
96
+ ### reactRefreshHost
97
+
98
+ 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:
99
+
100
+ ```js
101
+ react({ reactRefreshHost: 'http://localhost:3000' })
102
+ ```
103
+
104
+ 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}`.
105
+
96
106
  ### useAtYourOwnRisk_mutateSwcOptions
97
107
 
98
108
  The future of Vite is with OXC, and from the beginning this was a design choice to not exposed too many specialties from SWC so that Vite React users can move to another transformer later.
package/index.cjs CHANGED
@@ -17,7 +17,7 @@ window.$RefreshReg$ = () => {};
17
17
  window.$RefreshSig$ = () => (type) => type;`;
18
18
  var getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
19
19
  var 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
  `,
@@ -124,6 +124,7 @@ var react = (_options) => {
124
124
  plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
125
125
  devTarget: (_options == null ? void 0 : _options.devTarget) ?? "es2020",
126
126
  parserConfig: _options == null ? void 0 : _options.parserConfig,
127
+ reactRefreshHost: _options == null ? void 0 : _options.reactRefreshHost,
127
128
  useAtYourOwnRisk_mutateSwcOptions: _options == null ? void 0 : _options.useAtYourOwnRisk_mutateSwcOptions
128
129
  };
129
130
  return [
@@ -143,6 +144,8 @@ var react = (_options) => {
143
144
  apply: "serve",
144
145
  config: () => ({
145
146
  esbuild: false,
147
+ // NOTE: oxc option only exists in rolldown-vite
148
+ oxc: false,
146
149
  optimizeDeps: {
147
150
  include: [`${options.jsxImportSource}/jsx-dev-runtime`],
148
151
  esbuildOptions: { jsx: "automatic" }
@@ -187,7 +190,8 @@ var react = (_options) => {
187
190
  result.code,
188
191
  result.map,
189
192
  "@vitejs/plugin-react-swc",
190
- id
193
+ id,
194
+ options.reactRefreshHost
191
195
  );
192
196
  }
193
197
  },
package/index.d.ts CHANGED
@@ -29,6 +29,14 @@ type Options = {
29
29
  * Exclusion of node_modules should be handled by the function if needed.
30
30
  */
31
31
  parserConfig?: (id: string) => ParserConfig | undefined;
32
+ /**
33
+ * React Fast Refresh runtime URL prefix.
34
+ * Useful in a module federation context to enable HMR by specifying
35
+ * the host application URL in a Vite config of a remote application.
36
+ * @example
37
+ * reactRefreshHost: 'http://localhost:3000'
38
+ */
39
+ reactRefreshHost?: string;
32
40
  /**
33
41
  * The future of Vite is with OXC, and from the beginning this was a design choice
34
42
  * to not exposed too many specialties from SWC so that Vite React users can move to
package/index.mjs CHANGED
@@ -19,7 +19,7 @@ window.$RefreshReg$ = () => {};
19
19
  window.$RefreshSig$ = () => (type) => type;`;
20
20
  var getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
21
21
  var avoidSourceMapOption = Symbol();
22
- function addRefreshWrapper(code, map, pluginName, id) {
22
+ function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
23
23
  const hasRefresh = refreshContentRE.test(code);
24
24
  const onlyReactComp = !hasRefresh && reactCompRE.test(code);
25
25
  const normalizedMap = map === avoidSourceMapOption ? null : map;
@@ -60,7 +60,7 @@ if (import.meta.hot && !inWebWorker) {
60
60
  }
61
61
  }
62
62
  const sharedHead = removeLineBreaksIfNeeded(
63
- `import * as RefreshRuntime from "${runtimePublicPath}";
63
+ `import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
64
64
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
65
65
 
66
66
  `,
@@ -125,6 +125,7 @@ var react = (_options) => {
125
125
  plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
126
126
  devTarget: (_options == null ? void 0 : _options.devTarget) ?? "es2020",
127
127
  parserConfig: _options == null ? void 0 : _options.parserConfig,
128
+ reactRefreshHost: _options == null ? void 0 : _options.reactRefreshHost,
128
129
  useAtYourOwnRisk_mutateSwcOptions: _options == null ? void 0 : _options.useAtYourOwnRisk_mutateSwcOptions
129
130
  };
130
131
  return [
@@ -144,6 +145,8 @@ var react = (_options) => {
144
145
  apply: "serve",
145
146
  config: () => ({
146
147
  esbuild: false,
148
+ // NOTE: oxc option only exists in rolldown-vite
149
+ oxc: false,
147
150
  optimizeDeps: {
148
151
  include: [`${options.jsxImportSource}/jsx-dev-runtime`],
149
152
  esbuildOptions: { jsx: "automatic" }
@@ -188,7 +191,8 @@ var react = (_options) => {
188
191
  result.code,
189
192
  result.map,
190
193
  "@vitejs/plugin-react-swc",
191
- id
194
+ id,
195
+ options.reactRefreshHost
192
196
  );
193
197
  }
194
198
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitejs/plugin-react-swc",
3
- "version": "3.9.0-beta.2",
3
+ "version": "3.9.0",
4
4
  "license": "MIT",
5
5
  "author": "Arnaud Barré (https://github.com/ArnaudBarre)",
6
6
  "description": "Speed up your Vite dev server with SWC",
@@ -23,7 +23,7 @@
23
23
  },
24
24
  "homepage": "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc#readme",
25
25
  "dependencies": {
26
- "@swc/core": "^1.11.11"
26
+ "@swc/core": "^1.11.21"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "vite": "^4 || ^5 || ^6"