Transcrypt icon indicating copy to clipboard operation
Transcrypt copied to clipboard

Programmatic API

Open cspotcode opened this issue 1 year ago • 0 comments

Does transcrypt have a programmatic API?

I'd like to do something like this for a live-reload server:

from transcrypt import compilationApi
def requestHandler(req):
    # Suppose browser has made request to download localhost:3000/code/myproject.module.js
    moduleName = req.path.replace("/code/", "").replace(".js", "") # I know this logic is wrong, just simple for example
    return Response.text(compilationApi.compile(moduleName)).contentType("application/javascript")

If the compiled .js for myproject.module contains any import statements, they'll trigger other HTTP requests from the browser which will trigger other calls to requestHandler to compile those modules.

cspotcode avatar Feb 15 '25 16:02 cspotcode