How swappable is the Javascript code generation?

Hello.
Now that rescript has definitely switch paths with ocaml, and removed a lot of intricate features from it, I was wondering if it could be modified to generate other outputs. I’m particularly interested in Lua. Lua has a lot of shared semantics to Javascript: closures, first class functions, module system almost identical to CJS, etc.
How deeply integrated is the code generation into the compiler? Will it bee too hard to swap JS generation with Lua generation?