Hacker News new | ask | show | jobs
by jeshin 1420 days ago
on the note of babel, I don't usually do front end stuff but the other day I wanted to transpile one single javascript file to support older browsers, one time and then never again. I tried for like an hour and I could not figure out how to do it, without setting up like a whole environment/pipeline for it. My expectation going into it was "surely there's some sort of command that just lets you do input file -> output file", but i struggled until I just gave up and used their web demo thing to do it (which tbh I should have just done to begin with, but I had not anticipated it would be so difficult).

I mean I'm sure it's possible somehow, but it sure isn't obvious. And I get that this is not at all the usual use case for it, but still

2 comments

Babel transpiles js to browsers which are older than me. You should give it a try.
If it's only one file, you could just go to the Babel website where they have a playground and paste it in, voilĂ , converted for older browsers. Now place the output file wherever you want.
Not sure if they edited their comment (although it seems unlikely given that your comment was four hours later), but that sounds exactly like what they said they did. Maybe I'm old-fashioned, but the idea that I need to upload a plaintext file to have it converted to another plaintext file so I can download it instead of just having a command to run locally seems almost surreal.
There is a command to run locally, `babel`. It works in the command line as well as part of a build tool. It seemed me that the parent however didn't want to spend more time learning all that if they needed to convert just one file.
yeah, I did get it to transpile with the babel command, but I couldn't get it to accept the babel-env preset, so it just transpiled from modern javascript to modern javascript, which is not very useful