Compiling elm-format to JS?

Hi!

I’m working on a rewrite of https://html2elm.obtuse.io and also a couple of new tools where I generate Elm code as output. Writing a code generator which generates nice looking Elm is turning out to be pretty complex even for a subset of Elm. Running elm-format using a port would be ideal for me. Has anyone had success compiling elm-format with GHCJS or other Haskell → JS compilers?

1 Like

As someone with experience in compiling elm tools to JavaScript using GHCJS, I’d like to offer the following advice:

Try running it on a server first. Heroku is free and easy. GHCJS is very difficult to set up and use, and the code files it generates are enormous. You’ll also have to write a custom entrypoint to replace the command line interface. Lastly, there’s no guarantee that the Haskell codebase for elm-format will remain compatible with JavaScript compiler backends. This is for sure the hardest and least straightforward way to integrate elm-format into a web-based UI. I had to learn this hard way, and I hope at least that can be so you don’t have to!

2 Likes

Thanks for the reply @luke!

How enormous are the compiled files? I really want to do this on the client side and not on a server. It’s a dev tool so I’m fine even if the compiled JS is like 1-2MB gzipped.

If compiling to JS is not an option I’ll probably write a formatter which generates somewhat reasonable code and let the user run elm-format when they copy paste the code into their project.