Compiling/evaluating purescript at runtime

Hello,
I am new to Purescript and I would like to make a static site generator. I thought it would be nice to be able to include Purescript code in pages that would be automatically translated to Javascript; but for that I’d need to compile it at runtime, is there a way to do it?

Most websites that support something like this for compiled languages hit an HTTP API to compile the code. try.purescript.org exists (though I’m not sure what kind of throughput it can handle), otherwise you can host your own instance of it and call the appropriate API.

Otherwise, you can stage your build to compile and include your code examples at build time. Then you don’t need to do any compiling at all at runtime.

1 Like

Sorry, I really don’t want to make requests to external servers; I’d like everything to work on the user’s computer without depending on network access and server availability.

Including code examples at build time is also problematic in terms of user-friendliness; I’d like the Purescript compilation to be an optional feature for users who have Purescript, not to force all users to use it.

A crude solution would be to make a system call to the Purescript compiler, but I’m not sure how this works depending on the user’s Purescript installation (in my case for instance I don’t know how to call the compiler itself, I only have spago)

What I was hoping to find is an interface to the Purescript compiler from within Purescript, like hint in Haskell.

1 Like

There is no recent implementation of the PureScript compiler that runs in the browser, unfortunately.

1 Like