@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 +205 -259
- package/index.d.cts +57 -0
- package/index.d.ts +56 -53
- package/index.js +238 -0
- package/package.json +6 -7
- package/refresh-runtime.js +485 -265
- package/index.mjs +0 -293
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
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
42
|
-
|
|
40
|
+
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
|
41
|
+
const avoidSourceMapOption = Symbol();
|
|
43
42
|
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
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
|
-
|
|
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
|
-
|
|
80
|
-
|
|
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
|
-
|
|
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
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
-
|
|
104
|
+
return enabled ? code.replace(/\n/g, "") : code;
|
|
114
105
|
}
|
|
115
106
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
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
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
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
|
-
|
|
260
|
+
//#endregion
|
|
315
261
|
module.exports = src_default;
|
|
316
|
-
module.exports.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 };
|