Created
March 19, 2025 20:58
-
-
Save brandonkal/fbaa090278e3e6307a9c90744093f20f to your computer and use it in GitHub Desktop.
Text Replacer Vite Plugin
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function lorem(text) { | |
return `lorem ipsum text for "${text}" ipsum` | |
} | |
export function loremTransformPlugin() { | |
return { | |
name: 'vite-plugin-lorem-ipsum', | |
enforce: 'pre', | |
transform(code, id) { | |
if (!/\.(ts|js|svelte)$/.test(id)) return; | |
const transformedCode = code.replace(/\$\$\$(.*?)\$\$\$/gs, (_match, key) => { | |
const content = key.trim(); | |
return lorem(content); | |
}); | |
return { | |
code: transformedCode, | |
map: null, | |
}; | |
}, | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { loremTransformPlugin } from "./vite-plugin-lorem-ipsum.js"; | |
export default defineConfig(() => { | |
return { | |
plugins: [ | |
loremTransformPlugin(), | |
sveltekit(), | |
// rest of config here | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment