I’ve done this recently, but very hacky. so Svelte has the concept of pre-processors that take differently types of language like typescript, SCSS, Pug and turns it into JS, CSS and HTML in a preprocessing stage, so what’s roughly needed is way or documentation now how to turn Rescript code as string into JS as string, maybe a command that works with stdin and stdout. again below is very hacky but did work.
const rescriptPreprocess = () => {
return {
name: 'svelte-rescript',
/**
* @param {object} options
* @param {string} options.content
* @param {string} options.filename
* @param {object} options.attributes
* @param {'res'} options.attributes.lang
*/
script: async ({ content, attributes }) => {
if (attributes.lang == 'res') {
console.info('content', content)
const cmd = `./node_modules/.bin/bsc -bs-package-name svelte-rescript -bs-package-output esmodule:.:esmodule -o tmp -e "${content}"`;
await promisify(exec)(cmd);
const jsContent = readFileSync('tmpesmodule').toString();
return {
code: jsContent
};
}
}
};
};