@vitejs/plugin-react-swc 3.10.1 → 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/README.md +8 -0
- package/index.cjs +214 -238
- package/index.d.cts +57 -0
- package/index.d.ts +56 -49
- package/index.js +238 -0
- package/package.json +6 -7
- package/refresh-runtime.js +485 -265
- package/index.mjs +0 -286
package/README.md
CHANGED
|
@@ -117,6 +117,14 @@ react({
|
|
|
117
117
|
})
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
### disableOxcRecommendation
|
|
121
|
+
|
|
122
|
+
If set, disables the recommendation to use `@vitejs/plugin-react-oxc` (which is shown when `rolldown-vite` is detected and neither `swc` plugins are used nor the `swc` options are mutated).
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
react({ disableOxcRecommendation: true })
|
|
126
|
+
```
|
|
127
|
+
|
|
120
128
|
## Consistent components exports
|
|
121
129
|
|
|
122
130
|
For React refresh to work correctly, your file should only export React components. The best explanation I've read is the one from the [Gatsby docs](https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#how-it-works).
|
package/index.cjs
CHANGED
|
@@ -1,33 +1,57 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
6
|
-
var
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
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;
|
|
17
|
+
};
|
|
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));
|
|
22
|
+
|
|
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"));
|
|
7
31
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
1
|
|
14
|
-
)}";
|
|
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)}";
|
|
15
37
|
injectIntoGlobalHook(window);
|
|
16
38
|
window.$RefreshReg$ = () => {};
|
|
17
39
|
window.$RefreshSig$ = () => (type) => type;`;
|
|
18
|
-
|
|
19
|
-
|
|
40
|
+
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
|
41
|
+
const avoidSourceMapOption = Symbol();
|
|
20
42
|
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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;
|
|
31
55
|
let prevRefreshSig;
|
|
32
56
|
|
|
33
57
|
if (import.meta.hot && !inWebWorker) {
|
|
@@ -43,244 +67,196 @@ if (import.meta.hot && !inWebWorker) {
|
|
|
43
67
|
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
44
68
|
}
|
|
45
69
|
|
|
46
|
-
`,
|
|
47
|
-
|
|
48
|
-
);
|
|
49
|
-
newCode = `${refreshHead}${newCode}
|
|
70
|
+
`, avoidSourceMap);
|
|
71
|
+
newCode = `${refreshHead}${newCode}
|
|
50
72
|
|
|
51
73
|
if (import.meta.hot && !inWebWorker) {
|
|
52
74
|
window.$RefreshReg$ = prevRefreshReg;
|
|
53
75
|
window.$RefreshSig$ = prevRefreshSig;
|
|
54
76
|
}
|
|
55
77
|
`;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
}
|
|
60
|
-
const sharedHead = removeLineBreaksIfNeeded(
|
|
61
|
-
`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}";
|
|
62
81
|
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
63
82
|
|
|
64
|
-
`,
|
|
65
|
-
|
|
66
|
-
);
|
|
67
|
-
newCode = `${sharedHead}${newCode}
|
|
83
|
+
`, avoidSourceMap);
|
|
84
|
+
newCode = `${sharedHead}${newCode}
|
|
68
85
|
|
|
69
86
|
if (import.meta.hot && !inWebWorker) {
|
|
70
87
|
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
71
|
-
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(
|
|
72
|
-
id
|
|
73
|
-
)}, currentExports);
|
|
88
|
+
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
|
|
74
89
|
import.meta.hot.accept((nextExports) => {
|
|
75
90
|
if (!nextExports) return;
|
|
76
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(
|
|
77
|
-
id
|
|
78
|
-
)}, currentExports, nextExports);
|
|
91
|
+
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
|
|
79
92
|
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
80
93
|
});
|
|
81
94
|
});
|
|
82
95
|
}
|
|
83
96
|
`;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
97
|
+
if (newMap) newMap.mappings = ";;;" + newMap.mappings;
|
|
98
|
+
return {
|
|
99
|
+
code: newCode,
|
|
100
|
+
map: newMap
|
|
101
|
+
};
|
|
88
102
|
}
|
|
89
103
|
function removeLineBreaksIfNeeded(code, enabled) {
|
|
90
|
-
|
|
104
|
+
return enabled ? code.replace(/\n/g, "") : code;
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
if ((_b = (_a = userConfig.build) == null ? void 0 : _a.rollupOptions) == null ? void 0 : _b.onwarn) {
|
|
105
|
-
userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
106
|
-
} else {
|
|
107
|
-
defaultHandler(warning);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
});
|
|
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
|
+
} } });
|
|
112
115
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
return addRefreshWrapper(
|
|
204
|
-
result.code,
|
|
205
|
-
result.map,
|
|
206
|
-
"@vitejs/plugin-react-swc",
|
|
207
|
-
id,
|
|
208
|
-
options.reactRefreshHost
|
|
209
|
-
);
|
|
210
|
-
}
|
|
211
|
-
},
|
|
212
|
-
options.plugins ? {
|
|
213
|
-
name: "vite:react-swc",
|
|
214
|
-
apply: "build",
|
|
215
|
-
enforce: "pre",
|
|
216
|
-
// Run before esbuild
|
|
217
|
-
config: (userConfig) => ({
|
|
218
|
-
build: silenceUseClientWarning(userConfig)
|
|
219
|
-
}),
|
|
220
|
-
transform: (code, _id) => transformWithOptions(_id.split("?")[0], code, "esnext", options, {
|
|
221
|
-
runtime: "automatic",
|
|
222
|
-
importSource: options.jsxImportSource
|
|
223
|
-
})
|
|
224
|
-
} : {
|
|
225
|
-
name: "vite:react-swc",
|
|
226
|
-
apply: "build",
|
|
227
|
-
config: (userConfig) => ({
|
|
228
|
-
build: silenceUseClientWarning(userConfig),
|
|
229
|
-
esbuild: {
|
|
230
|
-
jsx: "automatic",
|
|
231
|
-
jsxImportSource: options.jsxImportSource,
|
|
232
|
-
tsconfigRaw: {
|
|
233
|
-
compilerOptions: { useDefineForClassFields: true }
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
}
|
|
238
|
-
];
|
|
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
|
+
];
|
|
239
206
|
};
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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;
|
|
281
257
|
};
|
|
282
258
|
var src_default = react;
|
|
283
259
|
|
|
284
|
-
|
|
260
|
+
//#endregion
|
|
285
261
|
module.exports = src_default;
|
|
286
|
-
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 };
|