compiler
compiler copied to clipboard
Feature request: emit compiled JS to stdout
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?
Thanks for reporting this! To set expectations:
- Issues are reviewed in batches, so it can take some time to get a response.
- Ask questions in a community forum. You will get an answer quicker that way!
- If you experience something similar, open a new issue. We like duplicates.
Finally, please be patient with the core team. They are trying their best with limited resources.
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:
- https://github.com/mdgriffith/elm-optimize-level-2/blob/35a0bede188cd0e9db9239755384a3677b27070f/src/index.ts#L38
- https://github.com/parcel-bundler/parcel/blob/7a441032e4cf1fa23dc28277e7330c60927b3798/packages/transformers/elm/src/ElmTransformer.js#L59
- https://github.com/phenax/esbuild-plugin-elm/blob/e04f355516d1566953b7cbed8be8d822f84cf714/index.js#L41
- https://github.com/hmsk/vite-plugin-elm/blob/c4a0c47879397397a2eee6b52b0504bccdba5471/src/index.ts#L374
- https://github.com/marc136/snowpack-plugin-elm/blob/3bd3c95e2fe89afa8894ab6c5a14468bc018d82d/elm-plugin.js#L121
- https://github.com/ulisses-alves/rollup-plugin-elm/blob/4c1e1a05de1d1d7c7f4535c3362f3853d46892ba/src/index.js#L49
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!
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".