user11451972
user11451972

Reputation:

Can I still use Babel to transpile JavaScript into ES2015?

I want to transpile my JavaScript to ES2015. We used to use Babel for that, but Babel has deprecated this in favor of their weird new black box @babel/preset-env that (as far as I can tell) does what it thinks is best instead of just doing what I tell it to do. My question is this: does babel still allow me to do that? If so, how? Ideally, the answer should not depend on my target. I might want to target an earlier version of JavaScript also.

I've read this related SO question and answer. How do I get Babel 6 to compile to ES5 javascript? The only answer listed there is highly upvoted but it doesn't answer the question at all. It's one of those "this is what you should really be doing" answers.

If babel no longer supports this configuration, then the correct answer to this question is "no".

Upvotes: 3

Views: 925

Answers (1)

Igor Bykov
Igor Bykov

Reputation: 2812

imho: @babel/preset-env is a great thing. It actually doesn't "decide for you". You tell it what you want & then it just does whatever is necessary to get your code to the goal.

What to do if I just want ES2015?

Just use @babel/preset-env without setting the target.

According to babel docs:

Sidenote, if no targets are specified, @babel/preset-env will transform all ECMAScript 2015+ code by default.

Upvotes: 2

Related Questions