elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.51k stars 656 forks source link

Feature request: emit compiled JS to stdout #2197

Open pravdomil opened 3 years ago

pravdomil commented 3 years ago

It looks that the old issue https://github.com/elm/compiler/issues/961 is closed, and we are not able to emit JS to stdout, so I'm creating new issue?

github-actions[bot] commented 3 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

lydell commented 3 years ago

The node-elm-compiler package has compileToString and compileToStringSync functions. They compile into a temporary file and then read that.

https://github.com/rtfeldman/node-elm-compiler/blob/5801685cf669c2217d8720fddf78dfabe7cf111a/src/index.ts#L118-L183

Those functions seem quite popular:

So I think it would make sense to support outputting to stdout directly in elm make. That avoids the temporary files, and probably the node-elm-compiler dependency altogether in some cases!

pravdomil commented 3 years ago

Also we can then pipe Elm into UglifyJS.

elm make src/Main.elm --optimize | uglifyjs --compress 'pure_funcs=...' | uglifyjs --mangle

Also we can check if stdout is pipe or not and based on that do "create index.html" or "print JS to stdout".