Babel “How to use it without using it?
- Tram Ho
Written by Pham Quang Hung
- "Fat arrow" minimizes the syntax of the function
- or as a "promise" to clear out the problem of callbacks
- or a "let" that replaces "var" sida
In order to be able to run code with the new ES6 syntax, the necessary condition is that the browser must support it, you can see the list of browsers that have caught up with the time via the following detailed website (and will not many people are surprised that IE does not support the distortion very much, red from top to bottom ..)
Because browsers are not uniform, few dare to use the new ES6 syntax. Because I missed it, I finished writing a good run on firefox, so I got sick when I tested in IE. So, just use the old one (ES5) for good …
Or! There is a tool, convert ES6 code you write, to old ES5 code. There is a tool that does the conversion with just three simple commands. There is a tool that can convert not only ES6, but also convert both Typescript, Coffeescript, etc.
Maybe you are interested
npm install --save-dev @ babel / core @ babel / cli @ babel / preset-env
npm install --save @ babel / polyfill
~> "Why is it so simple, every step has a lot of messy miscellaneous things?" It really looks a little messy, but it is all to help Babel do the things promised above, if inhaled. slightly deep and careful, we will see that it is not complicated:
- The @babel / cli is to "make the conversion with only three simple statements"
- The @babel / polyfill provided to Babel is capable of converting code for both ancient browsers to understand.
npm install --save-dev @ babel / preset-what-something
Source : Viblo