Quantcast
Channel: ReScript Forum - Latest posts
Viewing all articles
Browse latest Browse all 2592

Use ReScript with Svelte

$
0
0

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?

  1. Can you build a res file in memory with a reference to the current proejct dir, and just return the contents?
  2. Would you need a custom pre-preprocess step that finds these code blocks, creates hidden .custom/Svelte_App.res files, does rescript build and then during svelte just returns .custom/Svelte_App.res.js

Viewing all articles
Browse latest Browse all 2592

Trending Articles