I'm struggling to understand the importance of Babel here... So ES6 comes along and gives us fat arrow functions, shorter syntax etc. so why do we need to compile ES6 into traditional JS? Is it because there are older browsers out there that can't interpret new JS syntax? Or does it have something to do with keeping source code consistent? Bit of a noob question I know - but hey, I am noob! Any insight appreciated!
Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backward-compatible version of JavaScript in current and older browsers or environments. Babel's plugins allow you to use the new syntax, right now without waiting for browser support.
You must use Babel to be sure that everyone will be able to run your code, else you can develop without it.
babel-loader exposes a loader-builder utility that allows users to add custom handling of Babel's configuration for each file that it processes.
With JSX, it is easy to define UI components in React. JSX should not be implemented directly by browsers, but instead requires a compiler to transform it into ECMAScript. This is where Babel comes in. Babel acts as this compiler allowing us to leverage all the benefits of JSX while building React components.
While the answers here are all correct, Babel is not just about ES6 (ES2015). The ECMA standards committee has agreed to release yearly updates to the JavaScript language. Babel will always integrate the standards, whereas we don't know if all the browsers will, and if they do, whether they will be able to keep up with the changing standards.
With a transpiler like Babel, we can stay ahead of the web browsers and use new features of ECMAscript when they are released instead of waiting for the browser manufacturers to integrate the features, use polyfills, or whatever else. It also allows the end user to customize the features that they want to use and build their own version of the language.
To hear the creator of Babel talk about this, you can listen to this JavaScript Jabber episode.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With