前端入门

来源:互联网 发布:淘宝指数在哪 编辑:程序博客网 时间:2024/05/18 01:59

#Babel

Babel 是一个 JavaScript 编译器。用来编译 jsx ES15 ES6的语法进行转换。

ES2015 and beyond

Babel has support for the latest version of JavaScript through syntax transformers. These plugins allow you to use new syntax, right now without waiting for browser support. Check out our env preset to get started

you can install this preset with:

npm install --save-dev babel-preset-env

Polyfill

Since Babel only transforms syntax (like arrow functions), you can use babel-polyfill in order to support new globals such as Promise or new native methods like String.padStart (left-pad). It uses core-js and regenerator. Check out our babel-polyfill docs for more info.

npm install --save-dev babel-polyfill

JSX and Flow

Babel can convert JSX syntax and strip out type annotations. Check out our React preset to get started. Use it together with the babel-sublime package to bring syntax highlighting to a whole new level.

npm install --save-dev babel-preset-react

Babel CLI

While you can install Babel CLI globally on your machine, it’s much better to install it locally project by project.

There are two primary reasons for this.

Different projects on the same machine can depend on different versions of Babel allowing you to update one at a time.
It means you do not have an implicit dependency on the environment you are working in. Making your project far more portable and easier to setup.
We can install Babel CLI locally by running:

npm install --save-dev babel-cli
原创粉丝点击