@vitejs/plugin-react-swc 3.10.2 → 3.11.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/index.cjs CHANGED
@@ -1,3 +1,4 @@
1
+ //#region rolldown:runtime
1
2
  var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -5,52 +6,52 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
5
6
  var __getProtoOf = Object.getPrototypeOf;
6
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
8
  var __copyProps = (to, from, except, desc) => {
8
- if (from && typeof from === "object" || typeof from === "function") {
9
- for (let key of __getOwnPropNames(from))
10
- if (!__hasOwnProp.call(to, key) && key !== except)
11
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12
- }
13
- return to;
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
14
17
  };
15
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
16
- // If the importer is in node compatibility mode or this is not an ESM
17
- // file that has been converted to a CommonJS file using a Babel-
18
- // compatible transform (i.e. "__esModule" has not been set), then set
19
- // "default" to the CommonJS "module.exports" for node compatibility.
20
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
21
- mod
22
- ));
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
23
22
 
24
- // src/index.ts
25
- var import_node_fs = require("fs");
26
- var import_node_path = require("path");
27
- var import_node_url = require("url");
28
- var import_node_module = require("module");
29
- var import_core = require("@swc/core");
23
+ //#endregion
24
+ const node_fs = __toESM(require("node:fs"));
25
+ const node_path = __toESM(require("node:path"));
26
+ const node_url = __toESM(require("node:url"));
27
+ const node_module = __toESM(require("node:module"));
28
+ const __swc_core = __toESM(require("@swc/core"));
29
+ const vite = __toESM(require("vite"));
30
+ const __rolldown_pluginutils = __toESM(require("@rolldown/pluginutils"));
30
31
 
31
- // ../common/refresh-utils.ts
32
- var runtimePublicPath = "/@react-refresh";
33
- var reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
34
- var refreshContentRE = /\$RefreshReg\$\(/;
35
- var preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(
36
- 1
37
- )}";
32
+ //#region ../common/refresh-utils.ts
33
+ const runtimePublicPath = "/@react-refresh";
34
+ const reactCompRE = /extends\s+(?:React\.)?(?:Pure)?Component/;
35
+ const refreshContentRE = /\$RefreshReg\$\(/;
36
+ const preambleCode = `import { injectIntoGlobalHook } from "__BASE__${runtimePublicPath.slice(1)}";
38
37
  injectIntoGlobalHook(window);
39
38
  window.$RefreshReg$ = () => {};
40
39
  window.$RefreshSig$ = () => (type) => type;`;
41
- var getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
42
- var avoidSourceMapOption = Symbol();
40
+ const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
41
+ const avoidSourceMapOption = Symbol();
43
42
  function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
44
- const hasRefresh = refreshContentRE.test(code);
45
- const onlyReactComp = !hasRefresh && reactCompRE.test(code);
46
- const normalizedMap = map === avoidSourceMapOption ? null : map;
47
- if (!hasRefresh && !onlyReactComp) return { code, map: normalizedMap };
48
- const avoidSourceMap = map === avoidSourceMapOption;
49
- const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
50
- let newCode = code;
51
- if (hasRefresh) {
52
- const refreshHead = removeLineBreaksIfNeeded(
53
- `let prevRefreshReg;
43
+ const hasRefresh = refreshContentRE.test(code);
44
+ const onlyReactComp = !hasRefresh && reactCompRE.test(code);
45
+ const normalizedMap = map === avoidSourceMapOption ? null : map;
46
+ if (!hasRefresh && !onlyReactComp) return {
47
+ code,
48
+ map: normalizedMap
49
+ };
50
+ const avoidSourceMap = map === avoidSourceMapOption;
51
+ const newMap = typeof normalizedMap === "string" ? JSON.parse(normalizedMap) : normalizedMap;
52
+ let newCode = code;
53
+ if (hasRefresh) {
54
+ const refreshHead = removeLineBreaksIfNeeded(`let prevRefreshReg;
54
55
  let prevRefreshSig;
55
56
 
56
57
  if (import.meta.hot && !inWebWorker) {
@@ -66,251 +67,196 @@ if (import.meta.hot && !inWebWorker) {
66
67
  window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
67
68
  }
68
69
 
69
- `,
70
- avoidSourceMap
71
- );
72
- newCode = `${refreshHead}${newCode}
70
+ `, avoidSourceMap);
71
+ newCode = `${refreshHead}${newCode}
73
72
 
74
73
  if (import.meta.hot && !inWebWorker) {
75
74
  window.$RefreshReg$ = prevRefreshReg;
76
75
  window.$RefreshSig$ = prevRefreshSig;
77
76
  }
78
77
  `;
79
- if (newMap) {
80
- newMap.mappings = ";".repeat(16) + newMap.mappings;
81
- }
82
- }
83
- const sharedHead = removeLineBreaksIfNeeded(
84
- `import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
78
+ if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings;
79
+ }
80
+ const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
85
81
  const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
86
82
 
87
- `,
88
- avoidSourceMap
89
- );
90
- newCode = `${sharedHead}${newCode}
83
+ `, avoidSourceMap);
84
+ newCode = `${sharedHead}${newCode}
91
85
 
92
86
  if (import.meta.hot && !inWebWorker) {
93
87
  RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
94
- RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(
95
- id
96
- )}, currentExports);
88
+ RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
97
89
  import.meta.hot.accept((nextExports) => {
98
90
  if (!nextExports) return;
99
- const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(
100
- id
101
- )}, currentExports, nextExports);
91
+ const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
102
92
  if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
103
93
  });
104
94
  });
105
95
  }
106
96
  `;
107
- if (newMap) {
108
- newMap.mappings = ";;;" + newMap.mappings;
109
- }
110
- return { code: newCode, map: newMap };
97
+ if (newMap) newMap.mappings = ";;;" + newMap.mappings;
98
+ return {
99
+ code: newCode,
100
+ map: newMap
101
+ };
111
102
  }
112
103
  function removeLineBreaksIfNeeded(code, enabled) {
113
- return enabled ? code.replace(/\n/g, "") : code;
104
+ return enabled ? code.replace(/\n/g, "") : code;
114
105
  }
115
106
 
116
- // ../common/warning.ts
117
- var silenceUseClientWarning = (userConfig) => ({
118
- rollupOptions: {
119
- onwarn(warning, defaultHandler) {
120
- var _a, _b;
121
- if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) {
122
- return;
123
- }
124
- if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
125
- return;
126
- }
127
- if ((_b = (_a = userConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.onwarn) {
128
- userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
129
- } else {
130
- defaultHandler(warning);
131
- }
132
- }
133
- }
134
- });
107
+ //#endregion
108
+ //#region ../common/warning.ts
109
+ const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
110
+ if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) return;
111
+ if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) return;
112
+ if (userConfig.build?.rollupOptions?.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
113
+ else defaultHandler(warning);
114
+ } } });
135
115
 
136
- // src/index.ts
137
- var vite = __toESM(require("vite"), 1);
138
- var import_pluginutils = require("@rolldown/pluginutils");
139
- var import_meta = {};
140
- var _dirname = typeof __dirname !== "undefined" ? __dirname : (0, import_node_path.dirname)((0, import_node_url.fileURLToPath)(import_meta.url));
141
- var resolve = (0, import_node_module.createRequire)(
142
- typeof __filename !== "undefined" ? __filename : import_meta.url
143
- ).resolve;
144
- var react = (_options) => {
145
- let hmrDisabled = false;
146
- const options = {
147
- jsxImportSource: (_options == null ? void 0 : _options.jsxImportSource) ?? "react",
148
- tsDecorators: _options == null ? void 0 : _options.tsDecorators,
149
- plugins: (_options == null ? void 0 : _options.plugins) ? _options == null ? void 0 : _options.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
150
- devTarget: (_options == null ? void 0 : _options.devTarget) ?? "es2020",
151
- parserConfig: _options == null ? void 0 : _options.parserConfig,
152
- reactRefreshHost: _options == null ? void 0 : _options.reactRefreshHost,
153
- useAtYourOwnRisk_mutateSwcOptions: _options == null ? void 0 : _options.useAtYourOwnRisk_mutateSwcOptions,
154
- disableOxcRecommendation: _options == null ? void 0 : _options.disableOxcRecommendation
155
- };
156
- return [
157
- {
158
- name: "vite:react-swc:resolve-runtime",
159
- apply: "serve",
160
- enforce: "pre",
161
- // Run before Vite default resolve to avoid syscalls
162
- resolveId: {
163
- filter: { id: (0, import_pluginutils.exactRegex)(runtimePublicPath) },
164
- handler: (id) => id === runtimePublicPath ? id : void 0
165
- },
166
- load: {
167
- filter: { id: (0, import_pluginutils.exactRegex)(runtimePublicPath) },
168
- handler: (id) => id === runtimePublicPath ? (0, import_node_fs.readFileSync)(
169
- (0, import_node_path.join)(_dirname, "refresh-runtime.js"),
170
- "utf-8"
171
- ).replace(
172
- /__README_URL__/g,
173
- "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc"
174
- ) : void 0
175
- }
176
- },
177
- {
178
- name: "vite:react-swc",
179
- apply: "serve",
180
- config: () => ({
181
- esbuild: false,
182
- // NOTE: oxc option only exists in rolldown-vite
183
- oxc: false,
184
- optimizeDeps: {
185
- include: [`${options.jsxImportSource}/jsx-dev-runtime`],
186
- ..."rolldownVersion" in vite ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
187
- }
188
- }),
189
- configResolved(config) {
190
- if (config.server.hmr === false) hmrDisabled = true;
191
- const mdxIndex = config.plugins.findIndex(
192
- (p) => p.name === "@mdx-js/rollup"
193
- );
194
- if (mdxIndex !== -1 && mdxIndex > config.plugins.findIndex((p) => p.name === "vite:react-swc")) {
195
- throw new Error(
196
- "[vite:react-swc] The MDX plugin should be placed before this plugin"
197
- );
198
- }
199
- if ("rolldownVersion" in vite && !options.plugins && !options.useAtYourOwnRisk_mutateSwcOptions && !options.disableOxcRecommendation) {
200
- config.logger.warn(
201
- "[vite:react-swc] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance as no swc plugins are used. More information at https://vite.dev/rolldown"
202
- );
203
- }
204
- },
205
- transformIndexHtml: (_, config) => {
206
- if (!hmrDisabled) {
207
- return [
208
- {
209
- tag: "script",
210
- attrs: { type: "module" },
211
- children: getPreambleCode(config.server.config.base)
212
- }
213
- ];
214
- }
215
- },
216
- async transform(code, _id, transformOptions) {
217
- const id = _id.split("?")[0];
218
- const refresh = !(transformOptions == null ? void 0 : transformOptions.ssr) && !hmrDisabled;
219
- const result = await transformWithOptions(
220
- id,
221
- code,
222
- options.devTarget,
223
- options,
224
- {
225
- refresh,
226
- development: true,
227
- runtime: "automatic",
228
- importSource: options.jsxImportSource
229
- }
230
- );
231
- if (!result) return;
232
- if (!refresh) return result;
233
- return addRefreshWrapper(
234
- result.code,
235
- result.map,
236
- "@vitejs/plugin-react-swc",
237
- id,
238
- options.reactRefreshHost
239
- );
240
- }
241
- },
242
- options.plugins ? {
243
- name: "vite:react-swc",
244
- apply: "build",
245
- enforce: "pre",
246
- // Run before esbuild
247
- config: (userConfig) => ({
248
- build: silenceUseClientWarning(userConfig)
249
- }),
250
- transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, "esnext", options, {
251
- runtime: "automatic",
252
- importSource: options.jsxImportSource
253
- })
254
- } : {
255
- name: "vite:react-swc",
256
- apply: "build",
257
- config: (userConfig) => ({
258
- build: silenceUseClientWarning(userConfig),
259
- esbuild: {
260
- jsx: "automatic",
261
- jsxImportSource: options.jsxImportSource,
262
- tsconfigRaw: {
263
- compilerOptions: { useDefineForClassFields: true }
264
- }
265
- }
266
- })
267
- }
268
- ];
116
+ //#endregion
117
+ //#region src/index.ts
118
+ const _dirname = typeof __dirname !== "undefined" ? __dirname : (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
119
+ const resolve = (0, node_module.createRequire)(typeof __filename !== "undefined" ? __filename : require("url").pathToFileURL(__filename).href).resolve;
120
+ const react = (_options) => {
121
+ let hmrDisabled = false;
122
+ const options = {
123
+ jsxImportSource: _options?.jsxImportSource ?? "react",
124
+ tsDecorators: _options?.tsDecorators,
125
+ plugins: _options?.plugins ? _options?.plugins.map((el) => [resolve(el[0]), el[1]]) : void 0,
126
+ devTarget: _options?.devTarget ?? "es2020",
127
+ parserConfig: _options?.parserConfig,
128
+ reactRefreshHost: _options?.reactRefreshHost,
129
+ useAtYourOwnRisk_mutateSwcOptions: _options?.useAtYourOwnRisk_mutateSwcOptions,
130
+ disableOxcRecommendation: _options?.disableOxcRecommendation
131
+ };
132
+ return [
133
+ {
134
+ name: "vite:react-swc:resolve-runtime",
135
+ apply: "serve",
136
+ enforce: "pre",
137
+ resolveId: {
138
+ filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
139
+ handler: (id) => id === runtimePublicPath ? id : void 0
140
+ },
141
+ load: {
142
+ filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
143
+ handler: (id) => id === runtimePublicPath ? (0, node_fs.readFileSync)((0, node_path.join)(_dirname, "refresh-runtime.js"), "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react-swc") : void 0
144
+ }
145
+ },
146
+ {
147
+ name: "vite:react-swc",
148
+ apply: "serve",
149
+ config: () => ({
150
+ esbuild: false,
151
+ oxc: false,
152
+ optimizeDeps: {
153
+ include: [`${options.jsxImportSource}/jsx-dev-runtime`],
154
+ ..."rolldownVersion" in vite ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
155
+ }
156
+ }),
157
+ configResolved(config) {
158
+ if (config.server.hmr === false) hmrDisabled = true;
159
+ const mdxIndex = config.plugins.findIndex((p) => p.name === "@mdx-js/rollup");
160
+ if (mdxIndex !== -1 && mdxIndex > config.plugins.findIndex((p) => p.name === "vite:react-swc")) throw new Error("[vite:react-swc] The MDX plugin should be placed before this plugin");
161
+ if ("rolldownVersion" in vite && !options.plugins && !options.useAtYourOwnRisk_mutateSwcOptions && !options.disableOxcRecommendation) config.logger.warn("[vite:react-swc] We recommend switching to `@vitejs/plugin-react-oxc` for improved performance as no swc plugins are used. More information at https://vite.dev/rolldown");
162
+ },
163
+ transformIndexHtml: (_, config) => {
164
+ if (!hmrDisabled) return [{
165
+ tag: "script",
166
+ attrs: { type: "module" },
167
+ children: getPreambleCode(config.server.config.base)
168
+ }];
169
+ },
170
+ async transform(code, _id, transformOptions) {
171
+ const id = _id.split("?")[0];
172
+ const refresh = !transformOptions?.ssr && !hmrDisabled;
173
+ const result = await transformWithOptions(id, code, options.devTarget, options, {
174
+ refresh,
175
+ development: true,
176
+ runtime: "automatic",
177
+ importSource: options.jsxImportSource
178
+ });
179
+ if (!result) return;
180
+ if (!refresh) return result;
181
+ return addRefreshWrapper(result.code, result.map, "@vitejs/plugin-react-swc", id, options.reactRefreshHost);
182
+ }
183
+ },
184
+ options.plugins ? {
185
+ name: "vite:react-swc",
186
+ apply: "build",
187
+ enforce: "pre",
188
+ config: (userConfig) => ({ build: silenceUseClientWarning(userConfig) }),
189
+ transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, "esnext", options, {
190
+ runtime: "automatic",
191
+ importSource: options.jsxImportSource
192
+ })
193
+ } : {
194
+ name: "vite:react-swc",
195
+ apply: "build",
196
+ config: (userConfig) => ({
197
+ build: silenceUseClientWarning(userConfig),
198
+ esbuild: {
199
+ jsx: "automatic",
200
+ jsxImportSource: options.jsxImportSource,
201
+ tsconfigRaw: { compilerOptions: { useDefineForClassFields: true } }
202
+ }
203
+ })
204
+ }
205
+ ];
269
206
  };
270
- var transformWithOptions = async (id, code, target, options, reactConfig) => {
271
- const decorators = (options == null ? void 0 : options.tsDecorators) ?? false;
272
- const parser = options.parserConfig ? options.parserConfig(id) : id.endsWith(".tsx") ? { syntax: "typescript", tsx: true, decorators } : id.endsWith(".ts") || id.endsWith(".mts") ? { syntax: "typescript", tsx: false, decorators } : id.endsWith(".jsx") ? { syntax: "ecmascript", jsx: true } : id.endsWith(".mdx") ? (
273
- // JSX is required to trigger fast refresh transformations, even if MDX already transforms it
274
- { syntax: "ecmascript", jsx: true }
275
- ) : void 0;
276
- if (!parser) return;
277
- let result;
278
- try {
279
- const swcOptions = {
280
- filename: id,
281
- swcrc: false,
282
- configFile: false,
283
- sourceMaps: true,
284
- jsc: {
285
- target,
286
- parser,
287
- experimental: { plugins: options.plugins },
288
- transform: {
289
- useDefineForClassFields: true,
290
- react: reactConfig
291
- }
292
- }
293
- };
294
- if (options.useAtYourOwnRisk_mutateSwcOptions) {
295
- options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
296
- }
297
- result = await (0, import_core.transform)(code, swcOptions);
298
- } catch (e) {
299
- const message = e.message;
300
- const fileStartIndex = message.indexOf("\u256D\u2500[");
301
- if (fileStartIndex !== -1) {
302
- const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)\]/);
303
- if (match) {
304
- e.line = match[1];
305
- e.column = match[2];
306
- }
307
- }
308
- throw e;
309
- }
310
- return result;
207
+ const transformWithOptions = async (id, code, target, options, reactConfig) => {
208
+ const decorators = options?.tsDecorators ?? false;
209
+ const parser = options.parserConfig ? options.parserConfig(id) : id.endsWith(".tsx") ? {
210
+ syntax: "typescript",
211
+ tsx: true,
212
+ decorators
213
+ } : id.endsWith(".ts") || id.endsWith(".mts") ? {
214
+ syntax: "typescript",
215
+ tsx: false,
216
+ decorators
217
+ } : id.endsWith(".jsx") ? {
218
+ syntax: "ecmascript",
219
+ jsx: true
220
+ } : id.endsWith(".mdx") ? {
221
+ syntax: "ecmascript",
222
+ jsx: true
223
+ } : void 0;
224
+ if (!parser) return;
225
+ let result;
226
+ try {
227
+ const swcOptions = {
228
+ filename: id,
229
+ swcrc: false,
230
+ configFile: false,
231
+ sourceMaps: true,
232
+ jsc: {
233
+ target,
234
+ parser,
235
+ experimental: { plugins: options.plugins },
236
+ transform: {
237
+ useDefineForClassFields: true,
238
+ react: reactConfig
239
+ }
240
+ }
241
+ };
242
+ if (options.useAtYourOwnRisk_mutateSwcOptions) options.useAtYourOwnRisk_mutateSwcOptions(swcOptions);
243
+ result = await (0, __swc_core.transform)(code, swcOptions);
244
+ } catch (e) {
245
+ const message = e.message;
246
+ const fileStartIndex = message.indexOf("╭─[");
247
+ if (fileStartIndex !== -1) {
248
+ const match = message.slice(fileStartIndex).match(/:(\d+):(\d+)\]/);
249
+ if (match) {
250
+ e.line = match[1];
251
+ e.column = match[2];
252
+ }
253
+ }
254
+ throw e;
255
+ }
256
+ return result;
311
257
  };
312
258
  var src_default = react;
313
259
 
314
- // <stdin>
260
+ //#endregion
315
261
  module.exports = src_default;
316
- module.exports.default = src_default;
262
+ module.exports.default = module.exports
package/index.d.cts ADDED
@@ -0,0 +1,57 @@
1
+ import { JscTarget, Options, ParserConfig } from "@swc/core";
2
+ import { Plugin } from "vite";
3
+
4
+ //#region src/index.d.ts
5
+ type Options$1 = {
6
+ /**
7
+ * Control where the JSX factory is imported from.
8
+ * @default "react"
9
+ */
10
+ jsxImportSource?: string;
11
+ /**
12
+ * Enable TypeScript decorators. Requires experimentalDecorators in tsconfig.
13
+ * @default false
14
+ */
15
+ tsDecorators?: boolean;
16
+ /**
17
+ * Use SWC plugins. Enable SWC at build time.
18
+ * @default undefined
19
+ */
20
+ plugins?: [string, Record<string, any>][];
21
+ /**
22
+ * Set the target for SWC in dev. This can avoid to down-transpile private class method for example.
23
+ * For production target, see https://vite.dev/config/build-options.html#build-target
24
+ * @default "es2020"
25
+ */
26
+ devTarget?: JscTarget;
27
+ /**
28
+ * Override the default include list (.ts, .tsx, .mts, .jsx, .mdx).
29
+ * This requires to redefine the config for any file you want to be included.
30
+ * If you want to trigger fast refresh on compiled JS, use `jsx: true`.
31
+ * Exclusion of node_modules should be handled by the function if needed.
32
+ */
33
+ parserConfig?: (id: string) => ParserConfig | undefined;
34
+ /**
35
+ * React Fast Refresh runtime URL prefix.
36
+ * Useful in a module federation context to enable HMR by specifying
37
+ * the host application URL in a Vite config of a remote application.
38
+ * @example
39
+ * reactRefreshHost: 'http://localhost:3000'
40
+ */
41
+ reactRefreshHost?: string;
42
+ /**
43
+ * The future of Vite is with OXC, and from the beginning this was a design choice
44
+ * to not exposed too many specialties from SWC so that Vite React users can move to
45
+ * another transformer later.
46
+ * Also debugging why some specific version of decorators with some other unstable/legacy
47
+ * feature doesn't work is not fun, so we won't provide support for it, hence the name `useAtYourOwnRisk`
48
+ */
49
+ useAtYourOwnRisk_mutateSwcOptions?: (options: Options) => void;
50
+ /**
51
+ * If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
52
+ */
53
+ disableOxcRecommendation?: boolean;
54
+ };
55
+ declare const react: (_options?: Options$1) => Plugin[];
56
+ //#endregion
57
+ export { react as default };