vite-plugin-rnw 0.0.7 → 0.0.8-1
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 +1 -34
- package/dist/index.d.ts +5 -65
- package/dist/index.js +81 -324
- package/package.json +6 -22
- package/dist/index.cjs +0 -472
- package/dist/index.d.cts +0 -68
- package/dist/refresh-runtime.js +0 -648
package/dist/index.cjs
DELETED
|
@@ -1,472 +0,0 @@
|
|
|
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_path = __toESM(require("node:path"));
|
|
25
|
-
const node_url = __toESM(require("node:url"));
|
|
26
|
-
const node_fs = __toESM(require("node:fs"));
|
|
27
|
-
const vite = __toESM(require("vite"));
|
|
28
|
-
const __bunchtogether_vite_plugin_flow = __toESM(require("@bunchtogether/vite-plugin-flow"));
|
|
29
|
-
const vite_plugin_commonjs = __toESM(require("vite-plugin-commonjs"));
|
|
30
|
-
const __rolldown_pluginutils = __toESM(require("@rolldown/pluginutils"));
|
|
31
|
-
|
|
32
|
-
//#region src/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)}";
|
|
37
|
-
injectIntoGlobalHook(window);
|
|
38
|
-
window.$RefreshReg$ = () => {};
|
|
39
|
-
window.$RefreshSig$ = () => (type) => type;`;
|
|
40
|
-
const getPreambleCode = (base) => preambleCode.replace("__BASE__", base);
|
|
41
|
-
const avoidSourceMapOption = Symbol();
|
|
42
|
-
function addRefreshWrapper(code, map, pluginName, id, reactRefreshHost = "") {
|
|
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;
|
|
55
|
-
let prevRefreshSig;
|
|
56
|
-
|
|
57
|
-
if (import.meta.hot && !inWebWorker) {
|
|
58
|
-
if (!window.$RefreshReg$) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
"${pluginName} can't detect preamble. Something is wrong."
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
prevRefreshReg = window.$RefreshReg$;
|
|
65
|
-
prevRefreshSig = window.$RefreshSig$;
|
|
66
|
-
window.$RefreshReg$ = RefreshRuntime.getRefreshReg(${JSON.stringify(id)});
|
|
67
|
-
window.$RefreshSig$ = RefreshRuntime.createSignatureFunctionForTransform;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
`, avoidSourceMap);
|
|
71
|
-
newCode = `${refreshHead}${newCode}
|
|
72
|
-
|
|
73
|
-
if (import.meta.hot && !inWebWorker) {
|
|
74
|
-
window.$RefreshReg$ = prevRefreshReg;
|
|
75
|
-
window.$RefreshSig$ = prevRefreshSig;
|
|
76
|
-
}
|
|
77
|
-
`;
|
|
78
|
-
if (newMap) newMap.mappings = ";".repeat(16) + newMap.mappings;
|
|
79
|
-
}
|
|
80
|
-
const sharedHead = removeLineBreaksIfNeeded(`import * as RefreshRuntime from "${reactRefreshHost}${runtimePublicPath}";
|
|
81
|
-
const inWebWorker = typeof WorkerGlobalScope !== 'undefined' && self instanceof WorkerGlobalScope;
|
|
82
|
-
|
|
83
|
-
`, avoidSourceMap);
|
|
84
|
-
newCode = `${sharedHead}${newCode}
|
|
85
|
-
|
|
86
|
-
if (import.meta.hot && !inWebWorker) {
|
|
87
|
-
RefreshRuntime.__hmr_import(import.meta.url).then((currentExports) => {
|
|
88
|
-
RefreshRuntime.registerExportsForReactRefresh(${JSON.stringify(id)}, currentExports);
|
|
89
|
-
import.meta.hot.accept((nextExports) => {
|
|
90
|
-
if (!nextExports) return;
|
|
91
|
-
const invalidateMessage = RefreshRuntime.validateRefreshBoundaryAndEnqueueUpdate(${JSON.stringify(id)}, currentExports, nextExports);
|
|
92
|
-
if (invalidateMessage) import.meta.hot.invalidate(invalidateMessage);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
`;
|
|
97
|
-
if (newMap) newMap.mappings = ";;;" + newMap.mappings;
|
|
98
|
-
return {
|
|
99
|
-
code: newCode,
|
|
100
|
-
map: newMap
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
|
-
function removeLineBreaksIfNeeded(code, enabled) {
|
|
104
|
-
return enabled ? code.replace(/\n/g, "") : code;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
//#endregion
|
|
108
|
-
//#region src/transforms.ts
|
|
109
|
-
/**
|
|
110
|
-
* Code transformation utilities for fixing React Native package compatibility issues
|
|
111
|
-
*/
|
|
112
|
-
/**
|
|
113
|
-
* Analyzes require statements in code and maps them to module imports.
|
|
114
|
-
* Handles patterns like: varName = require('path').prop or require('path').default
|
|
115
|
-
*/
|
|
116
|
-
function analyzeRequireStatements(originalCode, exportedVars) {
|
|
117
|
-
const importMap = /* @__PURE__ */ new Map();
|
|
118
|
-
for (const varName of exportedVars) {
|
|
119
|
-
const requirePattern = new RegExp(`${varName}\\s*=\\s*[\\s\\S]*?require\\(['"]([^'"]+)['"]\\)(?:\\.([\\w]+))?`, "g");
|
|
120
|
-
const requireMatch = requirePattern.exec(originalCode);
|
|
121
|
-
if (requireMatch) {
|
|
122
|
-
const [, modulePath, prop] = requireMatch;
|
|
123
|
-
const key = `${modulePath}:${prop || "default"}`;
|
|
124
|
-
if (!importMap.has(key)) importMap.set(key, []);
|
|
125
|
-
importMap.get(key).push(varName);
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return importMap;
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Removes try/catch blocks that contain require statements and export let declarations.
|
|
132
|
-
* This cleans up the problematic CommonJS patterns.
|
|
133
|
-
*/
|
|
134
|
-
function removeTryCatchRequireBlocks(code) {
|
|
135
|
-
let transformed = code.replace(/try\s*\{[^{}]*?require\([^)]+\)[^{}]*?\}\s*catch[^{}]*?\{[^{}]*?\}/gs, "");
|
|
136
|
-
transformed = transformed.replace(/export let \w+;/g, "");
|
|
137
|
-
return transformed;
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Generates direct export statements from the import map.
|
|
141
|
-
* Creates modern ESM exports like: export { default as varName } from 'module';
|
|
142
|
-
*/
|
|
143
|
-
function generateDirectExports(importMap) {
|
|
144
|
-
let exports$1 = "";
|
|
145
|
-
for (const [key, vars] of importMap) {
|
|
146
|
-
const [modulePath, prop] = key.split(":");
|
|
147
|
-
if (prop === "default") for (const varName of vars) exports$1 += `export { default as ${varName} } from '${modulePath}';\n`;
|
|
148
|
-
else for (const varName of vars) exports$1 += `export { ${prop} as ${varName} } from '${modulePath}';\n`;
|
|
149
|
-
}
|
|
150
|
-
return exports$1;
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Transforms React Native Reanimated webUtils files to fix problematic
|
|
154
|
-
* export let + try/catch + require patterns by converting them to proper ESM.
|
|
155
|
-
*
|
|
156
|
-
* This transformation handles the incompatible module patterns in React Native Reanimated
|
|
157
|
-
* that cause build errors in Vite due to mixing CommonJS require() with ESM exports.
|
|
158
|
-
*/
|
|
159
|
-
function transformReanimatedWebUtils(toTransform, originalCode, id, isProduction) {
|
|
160
|
-
if (!isProduction || !id.includes("node_modules/react-native-reanimated") || !id.includes("ReanimatedModule/js-reanimated/webUtils") || !originalCode.includes("export let") || !originalCode.includes("try") || !originalCode.includes("require")) return toTransform;
|
|
161
|
-
const exportLetMatches = Array.from(originalCode.matchAll(/export let (\w+);/g));
|
|
162
|
-
const exportedVars = exportLetMatches.map((match) => match[1]);
|
|
163
|
-
if (exportedVars.length === 0) return toTransform;
|
|
164
|
-
const importMap = analyzeRequireStatements(originalCode, exportedVars);
|
|
165
|
-
toTransform = removeTryCatchRequireBlocks(toTransform);
|
|
166
|
-
const exports$1 = generateDirectExports(importMap);
|
|
167
|
-
if (exports$1) toTransform = `${toTransform}\n${exports$1}`;
|
|
168
|
-
return toTransform;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
//#endregion
|
|
172
|
-
//#region src/index.ts
|
|
173
|
-
const silenceUseClientWarning = (userConfig) => ({ rollupOptions: { onwarn(warning, defaultHandler) {
|
|
174
|
-
var _userConfig$build;
|
|
175
|
-
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && (warning.message.includes("use client") || warning.message.includes("use server"))) return;
|
|
176
|
-
if (warning.code === "SOURCEMAP_ERROR" && warning.message.includes("resolve original location") && warning.pos === 0) return;
|
|
177
|
-
if ((_userConfig$build = userConfig.build) === null || _userConfig$build === void 0 || (_userConfig$build = _userConfig$build.rollupOptions) === null || _userConfig$build === void 0 ? void 0 : _userConfig$build.onwarn) userConfig.build.rollupOptions.onwarn(warning, defaultHandler);
|
|
178
|
-
else defaultHandler(warning);
|
|
179
|
-
} } });
|
|
180
|
-
const _dirname = (0, node_path.dirname)((0, node_url.fileURLToPath)(require("url").pathToFileURL(__filename).href));
|
|
181
|
-
const refreshRuntimePath = (0, node_path.join)(_dirname, "refresh-runtime.js");
|
|
182
|
-
let babel;
|
|
183
|
-
async function loadBabel() {
|
|
184
|
-
if (!babel) babel = await import("@babel/core");
|
|
185
|
-
return babel;
|
|
186
|
-
}
|
|
187
|
-
const extensions = [
|
|
188
|
-
".web.js",
|
|
189
|
-
".web.ts",
|
|
190
|
-
".web.tsx",
|
|
191
|
-
".web.mjs",
|
|
192
|
-
".web.cjs",
|
|
193
|
-
".js",
|
|
194
|
-
".jsx",
|
|
195
|
-
".json",
|
|
196
|
-
".ts",
|
|
197
|
-
".tsx",
|
|
198
|
-
".mjs",
|
|
199
|
-
".cjs"
|
|
200
|
-
];
|
|
201
|
-
const defaultIncludeRE = /\.[tj]sx?$/;
|
|
202
|
-
const defaultExcludeRE = /\/node_modules\/(?!react-native|@react-native|expo|@expo)/;
|
|
203
|
-
const tsRE = /\.tsx?$/;
|
|
204
|
-
const getInitialOptions = (opts) => {
|
|
205
|
-
if (opts.jsxRuntime === "classic") if ("rolldownVersion" in vite) return { oxc: { jsx: {
|
|
206
|
-
runtime: "classic",
|
|
207
|
-
development: false
|
|
208
|
-
} } };
|
|
209
|
-
else return { esbuild: { jsx: "transform" } };
|
|
210
|
-
else return {
|
|
211
|
-
esbuild: {
|
|
212
|
-
jsx: "automatic",
|
|
213
|
-
jsxImportSource: opts.jsxImportSource
|
|
214
|
-
},
|
|
215
|
-
optimizeDeps: "rolldownVersion" in vite ? { rollupOptions: { jsx: { mode: "automatic" } } } : { esbuildOptions: { jsx: "automatic" } }
|
|
216
|
-
};
|
|
217
|
-
};
|
|
218
|
-
function rnw(opts = {}) {
|
|
219
|
-
var _opts$babel;
|
|
220
|
-
const include = opts.include ?? defaultIncludeRE;
|
|
221
|
-
const exclude = opts.exclude ?? defaultExcludeRE;
|
|
222
|
-
const filter = (0, vite.createFilter)(include, exclude);
|
|
223
|
-
const jsxImportSource = opts.jsxImportSource ?? "react";
|
|
224
|
-
const jsxImportRuntime = `${jsxImportSource}/jsx-runtime`;
|
|
225
|
-
const jsxImportDevRuntime = `${jsxImportSource}/jsx-dev-runtime`;
|
|
226
|
-
let runningInVite = false;
|
|
227
|
-
let isProduction = true;
|
|
228
|
-
let projectRoot = process.cwd();
|
|
229
|
-
let skipFastRefresh = true;
|
|
230
|
-
let runPluginOverrides;
|
|
231
|
-
let staticBabelOptions;
|
|
232
|
-
const importReactRE = /\bimport\s+(?:\*\s+as\s+)?React\b/;
|
|
233
|
-
const viteBabel = {
|
|
234
|
-
name: "vite:react-native-web-babel",
|
|
235
|
-
enforce: "pre",
|
|
236
|
-
config(_userConfig, env) {
|
|
237
|
-
var _initialOptions$optim;
|
|
238
|
-
const development = env.mode === "development";
|
|
239
|
-
const initialOptions = getInitialOptions(opts);
|
|
240
|
-
return {
|
|
241
|
-
...initialOptions,
|
|
242
|
-
define: {
|
|
243
|
-
global: "window",
|
|
244
|
-
DEV: JSON.stringify(development),
|
|
245
|
-
"global.__x": {},
|
|
246
|
-
_frameTimestamp: void 0,
|
|
247
|
-
_WORKLET: false,
|
|
248
|
-
__DEV__: JSON.stringify(development),
|
|
249
|
-
"process.env.NODE_ENV": JSON.stringify(process.env.NODE_ENV || env.mode),
|
|
250
|
-
EXPO_OS: JSON.stringify("web"),
|
|
251
|
-
"process.env.EXPO_OS": JSON.stringify("web"),
|
|
252
|
-
"global.Error": "Error"
|
|
253
|
-
},
|
|
254
|
-
optimizeDeps: {
|
|
255
|
-
...initialOptions.optimizeDeps,
|
|
256
|
-
esbuildOptions: {
|
|
257
|
-
...(_initialOptions$optim = initialOptions.optimizeDeps) === null || _initialOptions$optim === void 0 ? void 0 : _initialOptions$optim.esbuildOptions,
|
|
258
|
-
resolveExtensions: extensions,
|
|
259
|
-
loader: { ".js": "jsx" },
|
|
260
|
-
plugins: [(0, __bunchtogether_vite_plugin_flow.esbuildFlowPlugin)(/* @__PURE__ */ new RegExp(/\.(flow|jsx?)$/), (_path) => "jsx")]
|
|
261
|
-
}
|
|
262
|
-
},
|
|
263
|
-
build: { rollupOptions: {
|
|
264
|
-
treeshake: "safest",
|
|
265
|
-
plugins: [{
|
|
266
|
-
name: "nativewind-fix",
|
|
267
|
-
async transform(code, id) {
|
|
268
|
-
if (id.includes("react-native-css-interop")) return { moduleSideEffects: "no-treeshake" };
|
|
269
|
-
}
|
|
270
|
-
}]
|
|
271
|
-
} },
|
|
272
|
-
resolve: {
|
|
273
|
-
extensions,
|
|
274
|
-
alias: { "react-native": "react-native-web" }
|
|
275
|
-
}
|
|
276
|
-
};
|
|
277
|
-
},
|
|
278
|
-
configResolved(config) {
|
|
279
|
-
runningInVite = true;
|
|
280
|
-
projectRoot = config.root;
|
|
281
|
-
isProduction = config.isProduction;
|
|
282
|
-
skipFastRefresh = isProduction || config.command === "build" || config.server.hmr === false;
|
|
283
|
-
if ("jsxPure" in opts) config.logger.warnOnce("[@vitejs/plugin-react] jsxPure was removed. You can configure esbuild.jsxSideEffects directly.");
|
|
284
|
-
const hooks = config.plugins.map((plugin) => {
|
|
285
|
-
var _plugin$api;
|
|
286
|
-
return (_plugin$api = plugin.api) === null || _plugin$api === void 0 ? void 0 : _plugin$api.reactBabel;
|
|
287
|
-
}).filter(defined);
|
|
288
|
-
if (hooks.length > 0) runPluginOverrides = (babelOptions, context) => {
|
|
289
|
-
hooks.forEach((hook) => hook(babelOptions, context, config));
|
|
290
|
-
};
|
|
291
|
-
else if (typeof opts.babel !== "function") staticBabelOptions = createBabelOptions(opts.babel);
|
|
292
|
-
},
|
|
293
|
-
options(options) {
|
|
294
|
-
if (!runningInVite) {
|
|
295
|
-
options.jsx = {
|
|
296
|
-
mode: opts.jsxRuntime,
|
|
297
|
-
importSource: opts.jsxImportSource
|
|
298
|
-
};
|
|
299
|
-
return options;
|
|
300
|
-
}
|
|
301
|
-
},
|
|
302
|
-
transform: {
|
|
303
|
-
filter: { id: {
|
|
304
|
-
include: (0, __rolldown_pluginutils.makeIdFiltersToMatchWithQuery)(include),
|
|
305
|
-
exclude: [...exclude ? (0, __rolldown_pluginutils.makeIdFiltersToMatchWithQuery)(ensureArray(exclude)) : []]
|
|
306
|
-
} },
|
|
307
|
-
async handler(code, id, options) {
|
|
308
|
-
const [filepath] = id.split("?");
|
|
309
|
-
if (!filepath || !filter(filepath)) return;
|
|
310
|
-
const ssr = (options === null || options === void 0 ? void 0 : options.ssr) === true;
|
|
311
|
-
const babelOptions = (() => {
|
|
312
|
-
if (staticBabelOptions) return staticBabelOptions;
|
|
313
|
-
const newBabelOptions = createBabelOptions(typeof opts.babel === "function" ? opts.babel(id, { ssr }) : opts.babel);
|
|
314
|
-
runPluginOverrides === null || runPluginOverrides === void 0 || runPluginOverrides(newBabelOptions, {
|
|
315
|
-
id,
|
|
316
|
-
ssr
|
|
317
|
-
});
|
|
318
|
-
return newBabelOptions;
|
|
319
|
-
})();
|
|
320
|
-
const plugins = [...babelOptions.plugins];
|
|
321
|
-
const isJSX = filepath.endsWith("x");
|
|
322
|
-
const useFastRefresh = !skipFastRefresh && !ssr && (isJSX || (opts.jsxRuntime === "classic" ? importReactRE.test(code) : code.includes(jsxImportDevRuntime) || code.includes(jsxImportRuntime)));
|
|
323
|
-
if (useFastRefresh) plugins.push([await loadPlugin("react-refresh/babel"), { skipEnvCheck: true }]);
|
|
324
|
-
if (opts.jsxRuntime === "classic" && isJSX) {
|
|
325
|
-
if (!isProduction) plugins.push(await loadPlugin("@babel/plugin-transform-react-jsx-self"), await loadPlugin("@babel/plugin-transform-react-jsx-source"));
|
|
326
|
-
}
|
|
327
|
-
const parserPlugins = [...babelOptions.parserOpts.plugins];
|
|
328
|
-
if (!filepath.endsWith(".ts")) parserPlugins.push("jsx");
|
|
329
|
-
if (tsRE.test(filepath)) parserPlugins.push("typescript");
|
|
330
|
-
const babel$1 = await loadBabel();
|
|
331
|
-
let toTransform = code;
|
|
332
|
-
toTransform = transformReanimatedWebUtils(toTransform, code, id, isProduction);
|
|
333
|
-
const result = await babel$1.transformAsync(toTransform, {
|
|
334
|
-
...babelOptions,
|
|
335
|
-
root: projectRoot,
|
|
336
|
-
filename: id,
|
|
337
|
-
sourceFileName: filepath,
|
|
338
|
-
retainLines: getReactCompilerPlugin(plugins) != null ? false : !isProduction && isJSX && opts.jsxRuntime !== "classic",
|
|
339
|
-
parserOpts: {
|
|
340
|
-
...babelOptions.parserOpts,
|
|
341
|
-
sourceType: "module",
|
|
342
|
-
allowAwaitOutsideFunction: true,
|
|
343
|
-
plugins: parserPlugins
|
|
344
|
-
},
|
|
345
|
-
generatorOpts: {
|
|
346
|
-
...babelOptions.generatorOpts,
|
|
347
|
-
importAttributesKeyword: "with",
|
|
348
|
-
decoratorsBeforeExport: true
|
|
349
|
-
},
|
|
350
|
-
plugins,
|
|
351
|
-
sourceMaps: true
|
|
352
|
-
});
|
|
353
|
-
if (result) {
|
|
354
|
-
if (!useFastRefresh) return {
|
|
355
|
-
code: result.code,
|
|
356
|
-
map: result.map
|
|
357
|
-
};
|
|
358
|
-
return addRefreshWrapper(result.code, result.map, "@vitejs/plugin-react", id, opts.reactRefreshHost);
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
const dependencies = [
|
|
364
|
-
"react",
|
|
365
|
-
"react-dom",
|
|
366
|
-
jsxImportDevRuntime,
|
|
367
|
-
jsxImportRuntime
|
|
368
|
-
];
|
|
369
|
-
const staticBabelPlugins = typeof opts.babel === "object" ? ((_opts$babel = opts.babel) === null || _opts$babel === void 0 ? void 0 : _opts$babel.plugins) ?? [] : [];
|
|
370
|
-
const reactCompilerPlugin = getReactCompilerPlugin(staticBabelPlugins);
|
|
371
|
-
if (reactCompilerPlugin != null) {
|
|
372
|
-
const reactCompilerRuntimeModule = getReactCompilerRuntimeModule(reactCompilerPlugin);
|
|
373
|
-
dependencies.push(reactCompilerRuntimeModule);
|
|
374
|
-
}
|
|
375
|
-
const viteReactRefresh = {
|
|
376
|
-
name: "vite:react-native-web-refresh",
|
|
377
|
-
enforce: "pre",
|
|
378
|
-
config: (userConfig) => ({
|
|
379
|
-
build: silenceUseClientWarning(userConfig),
|
|
380
|
-
optimizeDeps: { include: dependencies },
|
|
381
|
-
resolve: { dedupe: ["react", "react-dom"] }
|
|
382
|
-
}),
|
|
383
|
-
resolveId: {
|
|
384
|
-
filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
|
|
385
|
-
handler(id) {
|
|
386
|
-
if (id === runtimePublicPath) return id;
|
|
387
|
-
}
|
|
388
|
-
},
|
|
389
|
-
load: {
|
|
390
|
-
filter: { id: (0, __rolldown_pluginutils.exactRegex)(runtimePublicPath) },
|
|
391
|
-
handler(id) {
|
|
392
|
-
if (id === runtimePublicPath) return (0, node_fs.readFileSync)(refreshRuntimePath, "utf-8").replace(/__README_URL__/g, "https://github.com/vitejs/vite-plugin-react/tree/main/packages/plugin-react");
|
|
393
|
-
}
|
|
394
|
-
},
|
|
395
|
-
transformIndexHtml(_, config) {
|
|
396
|
-
if (!skipFastRefresh) return [{
|
|
397
|
-
tag: "script",
|
|
398
|
-
attrs: { type: "module" },
|
|
399
|
-
children: getPreambleCode(config.server.config.base)
|
|
400
|
-
}];
|
|
401
|
-
}
|
|
402
|
-
};
|
|
403
|
-
return [
|
|
404
|
-
(0, __bunchtogether_vite_plugin_flow.flowPlugin)({ exclude }),
|
|
405
|
-
{
|
|
406
|
-
name: "treat-js-files-as-jsx",
|
|
407
|
-
async transform(code, id) {
|
|
408
|
-
if (!id.match(/\.js$/)) return null;
|
|
409
|
-
return vite.transformWithEsbuild(code, id, {
|
|
410
|
-
loader: "jsx",
|
|
411
|
-
jsx: "automatic"
|
|
412
|
-
});
|
|
413
|
-
}
|
|
414
|
-
},
|
|
415
|
-
(0, vite_plugin_commonjs.default)(),
|
|
416
|
-
viteBabel,
|
|
417
|
-
viteReactRefresh
|
|
418
|
-
];
|
|
419
|
-
}
|
|
420
|
-
rnw.preambleCode = preambleCode;
|
|
421
|
-
const loadedPlugin = /* @__PURE__ */ new Map();
|
|
422
|
-
function loadPlugin(path) {
|
|
423
|
-
const cached = loadedPlugin.get(path);
|
|
424
|
-
if (cached) return cached;
|
|
425
|
-
const promise = import(path).then((module$1) => {
|
|
426
|
-
const value = module$1.default || module$1;
|
|
427
|
-
loadedPlugin.set(path, value);
|
|
428
|
-
return value;
|
|
429
|
-
});
|
|
430
|
-
loadedPlugin.set(path, promise);
|
|
431
|
-
return promise;
|
|
432
|
-
}
|
|
433
|
-
function createBabelOptions(rawOptions) {
|
|
434
|
-
var _babelOptions$parserO;
|
|
435
|
-
const babelOptions = {
|
|
436
|
-
babelrc: false,
|
|
437
|
-
configFile: false,
|
|
438
|
-
...rawOptions
|
|
439
|
-
};
|
|
440
|
-
babelOptions.plugins || (babelOptions.plugins = []);
|
|
441
|
-
babelOptions.presets || (babelOptions.presets = []);
|
|
442
|
-
babelOptions.overrides || (babelOptions.overrides = []);
|
|
443
|
-
babelOptions.parserOpts || (babelOptions.parserOpts = {});
|
|
444
|
-
(_babelOptions$parserO = babelOptions.parserOpts).plugins || (_babelOptions$parserO.plugins = []);
|
|
445
|
-
return babelOptions;
|
|
446
|
-
}
|
|
447
|
-
function defined(value) {
|
|
448
|
-
return value !== void 0;
|
|
449
|
-
}
|
|
450
|
-
function getReactCompilerPlugin(plugins) {
|
|
451
|
-
return plugins.find((p) => p === "babel-plugin-react-compiler" || Array.isArray(p) && p[0] === "babel-plugin-react-compiler");
|
|
452
|
-
}
|
|
453
|
-
function getReactCompilerRuntimeModule(plugin) {
|
|
454
|
-
let moduleName = "react/compiler-runtime";
|
|
455
|
-
if (Array.isArray(plugin)) {
|
|
456
|
-
var _plugin$, _plugin$2, _plugin$3;
|
|
457
|
-
if (((_plugin$ = plugin[1]) === null || _plugin$ === void 0 ? void 0 : _plugin$.target) === "17" || ((_plugin$2 = plugin[1]) === null || _plugin$2 === void 0 ? void 0 : _plugin$2.target) === "18") moduleName = "react-compiler-runtime";
|
|
458
|
-
else if (typeof ((_plugin$3 = plugin[1]) === null || _plugin$3 === void 0 ? void 0 : _plugin$3.runtimeModule) === "string") {
|
|
459
|
-
var _plugin$4;
|
|
460
|
-
moduleName = (_plugin$4 = plugin[1]) === null || _plugin$4 === void 0 ? void 0 : _plugin$4.runtimeModule;
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
return moduleName;
|
|
464
|
-
}
|
|
465
|
-
function ensureArray(value) {
|
|
466
|
-
return Array.isArray(value) ? value : [value];
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
//#endregion
|
|
470
|
-
exports.rnw = rnw;
|
|
471
|
-
exports.silenceUseClientWarning = silenceUseClientWarning;
|
|
472
|
-
module.exports.default = module.exports
|
package/dist/index.d.cts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { ParserOptions, TransformOptions } from "@babel/core";
|
|
2
|
-
import { BuildOptions, Plugin, ResolvedConfig, UserConfig } from "vite";
|
|
3
|
-
|
|
4
|
-
//#region src/index.d.ts
|
|
5
|
-
declare const silenceUseClientWarning: (userConfig: UserConfig) => BuildOptions;
|
|
6
|
-
interface Options {
|
|
7
|
-
include?: string | RegExp | Array<string | RegExp>;
|
|
8
|
-
exclude?: string | RegExp | Array<string | RegExp>;
|
|
9
|
-
/**
|
|
10
|
-
* Control where the JSX factory is imported from.
|
|
11
|
-
* https://esbuild.github.io/api/#jsx-import-source
|
|
12
|
-
* @default 'react'
|
|
13
|
-
*/
|
|
14
|
-
jsxImportSource?: string;
|
|
15
|
-
/**
|
|
16
|
-
* Note: Skipping React import with classic runtime is not supported from v4
|
|
17
|
-
* @default "automatic"
|
|
18
|
-
*/
|
|
19
|
-
jsxRuntime?: "classic" | "automatic";
|
|
20
|
-
/**
|
|
21
|
-
* Babel configuration applied in both dev and prod.
|
|
22
|
-
*/
|
|
23
|
-
babel?: BabelOptions | ((id: string, options: {
|
|
24
|
-
ssr?: boolean;
|
|
25
|
-
}) => BabelOptions);
|
|
26
|
-
/**
|
|
27
|
-
* React Fast Refresh runtime URL prefix.
|
|
28
|
-
* Useful in a module federation context to enable HMR by specifying
|
|
29
|
-
* the host application URL in the Vite config of a remote application.
|
|
30
|
-
* @example
|
|
31
|
-
* reactRefreshHost: 'http://localhost:3000'
|
|
32
|
-
*/
|
|
33
|
-
reactRefreshHost?: string;
|
|
34
|
-
/**
|
|
35
|
-
* If set, disables the recommendation to use `@vitejs/plugin-react-oxc`
|
|
36
|
-
*/
|
|
37
|
-
disableOxcRecommendation?: boolean;
|
|
38
|
-
}
|
|
39
|
-
type BabelOptions = Omit<TransformOptions, "ast" | "filename" | "root" | "sourceFileName" | "sourceMaps" | "inputSourceMap">;
|
|
40
|
-
/**
|
|
41
|
-
* The object type used by the `options` passed to plugins with
|
|
42
|
-
* an `api.reactBabel` method.
|
|
43
|
-
*/
|
|
44
|
-
interface ReactBabelOptions extends BabelOptions {
|
|
45
|
-
plugins: Extract<BabelOptions["plugins"], any[]>;
|
|
46
|
-
presets: Extract<BabelOptions["presets"], any[]>;
|
|
47
|
-
overrides: Extract<BabelOptions["overrides"], any[]>;
|
|
48
|
-
parserOpts: ParserOptions & {
|
|
49
|
-
plugins: Extract<ParserOptions["plugins"], any[]>;
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
type ReactBabelHook = (babelConfig: ReactBabelOptions, context: ReactBabelHookContext, config: ResolvedConfig) => void;
|
|
53
|
-
type ReactBabelHookContext = {
|
|
54
|
-
ssr: boolean;
|
|
55
|
-
id: string;
|
|
56
|
-
};
|
|
57
|
-
type ViteReactPluginApi = {
|
|
58
|
-
/**
|
|
59
|
-
* Manipulate the Babel options of `@vitejs/plugin-react`
|
|
60
|
-
*/
|
|
61
|
-
reactBabel?: ReactBabelHook;
|
|
62
|
-
};
|
|
63
|
-
declare function rnw(opts?: Options): Plugin[];
|
|
64
|
-
declare namespace rnw {
|
|
65
|
-
var preambleCode: string;
|
|
66
|
-
}
|
|
67
|
-
//#endregion
|
|
68
|
-
export { BabelOptions, Options, ReactBabelOptions, ViteReactPluginApi, rnw, silenceUseClientWarning };
|