Is it possible to use Ecmascript 6 without Babel or Webpack?

Asked

Viewed 71 times

1

As in the old days, it would be possible to simply include an Ecmascript 6 file in the browser and use its functionalities without the need to "transpose" these codes?

1 answer

1

With the exception of Internet Explorer, most browsers support ES6, ES2016, ES2017 and ES2018 syntax.

Yes, it is possible to write the code directly without transpilator. Is it recommended? This is subjective.

Sites like W3schools and MDN often document what features are supported by each browser, but even these sites do not have complete documentation, at the end of the day it is up to you to juggle what should be done.

From experience (i.e., subjective), I believe that arrow function, async/await, for..of, spread operator, let/const are relatively safe to use directly in browsers. import/export on the other hand is not supported by any browser.

  • Welcome to Stackoverflow. Thank you for your reply, but it gave me a question. I was searching and saw that it is possible to use import and export including the script tag as follows: <script src="main.js" type="module"></script>. This would still be ES6?

  • They are not equivalent. import and export are macros to import modules, mainly used in Nodejs, in a similar way to import and public of other programming languages.

  • I found on this site: https://jakearchibald.com/2017/es-modules-in-browsers/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.