Home > Web Front-end > JS Tutorial > A simple way to convert es6 syntax to es5 using babel

A simple way to convert es6 syntax to es5 using babel

小云云
Release: 2018-01-05 10:47:14
Original
2887 people have browsed it

Babel is a widely used transcoder. Babel can perfectly convert ES6 code into ES5 code. This article mainly introduces the relevant information about using Babel to convert es6 syntax to es5. The article introduces it very well through examples. For details, friends in need can refer to it. Hope it helps everyone.

Preface

Babel is a widely used transcoder that can convert ES6 code into ES5 code so that it can be executed in the existing environment.

This means that you can write programs in ES6 now without worrying about whether the existing environment supports it.

This article explains that node and npm need to be pre-installed. You can refer to this article: http://www.jb51.net/article/90518.htm, which is very detailed.

File directory structure


Generate package management configuration file package.json

npm init -y
Copy after login

Installation conversion Tool

npm i -g babel-cli

npm i --save-dev babel-preset-es2015 babel-cli
Copy after login

Write the following content in the .babelrc file

{
 "presets": [
 "es2015"
 ],
 "plugins": []
}
Copy after login

Compile file

babel src/test.js -o dist/test.js
Copy after login

Related recommendations:

Detailed explanation of the super keyword in ES6 Class

Webstorm's new .vue file supports highlighted vue syntax and es6 syntax

ES6 What are the functions of static methods in classes

The above is the detailed content of A simple way to convert es6 syntax to es5 using babel. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template