Home  >  Article  >  Web Front-end  >  How to use babel to convert es6 syntax to es5

How to use babel to convert es6 syntax to es5

亚连
亚连Original
2018-06-23 14:27:191411browse

Babel is a widely used transcoder. Babel can perfectly convert ES6 code to ES5 code, so the following article will give you a detailed introduction to the relevant information about using babel to convert es6 syntax to es5. Article The introduction is very detailed through examples, friends in need can refer to it.

Preface

Babel is a widely used transcoder that can convert ES6 code to 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: //www.jb51.net/article/90518.htm, which is introduced in great detail.

File directory structure

##Generate package management configuration file package.json

npm init -y

Install the conversion tool

npm i -g babel-cli

npm i --save-dev babel-preset-es2015 babel-cli

Write the following content in the .babelrc file

{
 "presets": [
 "es2015"
 ],
 "plugins": []
}

Compile the file

babel src/test.js -o dist/test.js

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

How to use JavaScript to achieve provincial and municipal linkage

How to use the watcher in vue

How to use calculated properties in vue

How to export json data to Excel spreadsheet in Vue

In WeChat Usage of tabBar in mini program (detailed tutorial)

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

Statement:
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