one
Version:
One is a new React Framework that makes Vite serve both native and web.
32 lines (31 loc) • 1.06 kB
JavaScript
var routeIdReturnRegex = /return\s*["'`]\.\/[^"'`]+["'`]/;
var routeIdReturnRegexFor = function (routeId) {
return new RegExp(`return\\s*["'\`]${routeId.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}["'\`]`);
};
function replaceLoader(param) {
var {
code,
loaderData,
routeId
} = param;
var stringifiedData = JSON.stringify(loaderData);
var safeData = stringifiedData.replace(/\$/g, "$$$$");
var out = function () {
if (code.includes("__vxrn__loader__")) {
return code.replace(/["']__vxrn__loader__['"]/,
// make sure this ' ' is added in front,
// minifiers will do `return"something"
// but if its null then it becomes returnnull
" " + safeData);
}
var stubRegex = routeId ? routeIdReturnRegexFor(routeId) : routeIdReturnRegex;
if (stubRegex.test(code)) {
return code.replace(stubRegex, "return " + safeData);
}
return code + `
export const loader = () => (${stringifiedData})`;
}();
return out;
}
export { replaceLoader };
//# sourceMappingURL=replaceLoader.native.js.map