So Svelte has docs on their preprocessor, which easily lets you access and replace content within the <script> tag. So in your .svelte file, you can do:
<script lang="res">
Console.log("Hello World");
</script>
And in the build plugin you can access the code block easily during their build step:
preprocess: {
script: ({ content, attributes }) => {
if (attributes.lang !== "res") return;
console.log("This file is a res file", content);
},
},
transforming (1) src/main.js This file is a res file
Console.log("Hello World");
The question though is what approach you can take on the rescript side?
- Can you build a res file in memory with a reference to the current proejct dir, and just return the contents?
- Would you need a custom pre-preprocess step that finds these code blocks, creates hidden
.custom/Svelte_App.resfiles, doesrescript buildand then during svelte just returns.custom/Svelte_App.res.js