Home > Article > Web Front-end > How to use babel to convert es6 syntax to es5
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.jsThe 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 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!