one
Version:
One is a new React Framework that makes Vite serve both native and web.
25 lines (22 loc) • 586 B
text/typescript
export function replaceLoader({
code,
loaderData,
}: {
code: string
loaderData: Object
}) {
const stringifiedData = JSON.stringify(loaderData)
const out = (() => {
if (!code.includes('__vxrn__loader__')) {
return code + `\nexport const loader = () => (${stringifiedData})`
}
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
' ' + stringifiedData.replace(/\$/g, '$$$$')
)
})()
return out
}