babel(一)
一、babel
npm babel src/index.js -d lib
二、@babel/core @babel/cli
@babel/core 转换语法核心
@babel/cli 执行脚本
三、@babel/preset-env
四、babel-pollyfill
npm install --save @babel/polyfill
The @babel/polyfill module includes core-js and a custom regenerator runtime to emulate a full ES2015+ environment.
This means you can use new built-ins like Promise
or WeakMap
, static methods like Array.from
or Object.assign
, instance methods like Array.prototype.includes
, and generator functions (provided you use the regenerator plugin). The polyfill adds to the global scope as well as native prototypes like String
in order to do this.
For library/tool authors this may be too much. If you don't need the instance methods like Array.prototype.includes
you can do without polluting the global scope altogether by using the transform runtime plugin instead of @babel/polyfill
.
To go one step further, if you know exactly what features you need polyfills for, you can require them directly from core-js.
Now luckily for us, we're using the env
preset which has a "useBuiltIns"
option that when set to "usage"
will practically apply the last optimization mentioned above where you only include the polyfills you need. With this new option the configuration changes like this:
If we weren't using the env
preset with the "useBuiltIns"
option set to "usage"
we would've had to require the full polyfill only once in our entry point before any other code.
三、transform-runtime
We have separated out Babel's helpers from it's "polyfilling" behavior in runtime. More details in the PR.
@babel/runtime
now only contains the helpers, and if you need core-js
you can use @babel/runtime-corejs2
and the option provided in the transform. For both you still need the @babel/plugin-transform-runtime
This PR splits our setup into two separate runtimes:
'plugins': [
['transform-runtime'],
]
with npm install --save @babel/runtime that just includes our helpers, and relies on users to globally polyfill any APIs they need.
'plugins': [
['transform-runtime', { corejs: 2 }],
]
with npm install --save @babel/runtime-corejs2 that includes everything @babel/runtime does, but also includes a passthrough API for corejs@2.x and rewrites all of the helper modules to reference core-js.
@babel/runtime
is a library that contain's Babel modular runtime helpers and a version of regenerator-runtime
.
具体作用地址: https://babeljs.io/docs/en/babel-runtime
@babel/runtime-corejs2
is a library that contain's Babel modular runtime helpers and a version of regenerator-runtime
as well as core-js
.
Difference from @babel/runtime
This can be used instead of a polyfill for any non-instance methods. It will replace things like Promise
or Symbol
with the library functions in core-js
.
具体作用地址: https://babeljs.io/docs/en/babel-runtime-corejs2
五、plugins
- Plugins run before Presets.
- Plugin ordering is first to last.
- Preset ordering is reversed (last to first).
{ "plugins": ["pluginA", ["pluginA"], ["pluginA", {}]] }
六、presets
- Stage 0 - Strawman: just an idea, possible Babel plugin.
- Stage 1 - Proposal: this is worth working on.
- Stage 2 - Draft: initial spec.
- Stage 3 - Candidate: complete spec and initial browser implementations.
- Stage 4 - Finished: will be added to the next yearly release.
{ "presets": [ "presetA", ["presetA"], ["presetA", {}], ] }
babel(一)的更多相关文章
- babel presets stage-x
在一些新框架的代码中,常基于es6/7标准来书写代码.鉴于这些标准被没有被浏览器广泛支持,我们一般使用babel来将使用e6/7标准书写的代码降级编译(或者说转译)为浏览器可解析的es4/5代码. 以 ...
- ES6转换器之Babel
ES6部分功能没有支持,所以想学习ES6,得先有个转换器,就是将ES6的代码转换为ES5. 我这里用的是Gulp + Bable的形式来将ES6转换为ES5的. 前提: (1).Gulp和Bable都 ...
- Babel:JavaScript编译器
一.介绍: Babel是一个Javascript编译器,可以将ES6语法转换成ES5. 这意味着,你可以现在就用ES6编写程序,而不用担心现有环境是否支持.下面是一个例子: //转码前: input. ...
- 学习 React(jsx语法) + es2015 + babel + webpack
视频学习地址: http://www.jtthink.com/course/play/575 官方地址 https://facebook.github.io/react/ 神坑: 1.每次this.s ...
- Sublime插件支持Sass编译和Babel解析ES6 & .sublime-build文件初探
用Sublime Text蛮久了,配置配来配去的,每次换电脑都得重头再配过,奈何人老了脑子不中用了,得好好整理一些,下次换电脑就有得参考了.. 同事说,他的WebStorm简直太方便,自身集成了很多方 ...
- Babel下的ES6兼容性与规范
前端开发 Babel下的ES6兼容性与规范 ES6标准发布后,前端人员也开发渐渐了解到了es6,但是由于兼容性的问题,仍然没有得到广泛的推广,不过业界也用了一些折中性的方案来解决兼容性和开发体系问 ...
- 【前端】在Gulp中使用Babel
Install $ npm install --save-dev gulp-babel babel-preset-es2015 用法1: const gulp = require('gulp'); c ...
- 使用 Babel + React + Webpack 搭建 Web 应用
话不说直接上正题. 环境搭建 Babel--目前浏览器对于ES6的语法解析支持度还不高,所以要通过转码在编译,所以在使用ES6之前要安装Babel,之前安装的时候遇到了一些问题但是没有全部记录下来,现 ...
- Babel 学习
一,为了更明白地使用Babel, 先了解Babel 的发展过程. 现在Babel的版本是6, 相对于以前的版本, 它做了重大更新: 1, 模块化:所有的内部组件都变成了单独的包.打开Babel在Git ...
- 利用Babel来转化你的ES2015脚本初步
我们在前面已经安装和学习过babel 安装babel-cli 这是babel解释器的客户端主程序 npm install -g babel-cli 安装”编译”插件(babel的JSX语法转换器) n ...
随机推荐
- 《Java大学教程》--第3章 迭代
迭代(iteration).重复(repetition):三种循环* for: 重复执行固定次数* while: 重复执行不固定次数* do...while: 比while至少多一次 1.答:P47迭 ...
- 强化学习(一)—— 基本概念及马尔科夫决策过程(MDP)
1.策略与环境模型 强化学习是继监督学习和无监督学习之后的第三种机器学习方法.强化学习的整个过程如下图所示: 具体的过程可以分解为三个步骤: 1)根据当前的状态 $s_t$ 选择要执行的动作 $ a_ ...
- C#—ASP.NET:集成极光推送(Push API v3)
C#—ASP.NET:集成极光推送(Push API v3) 原文地址: https://blog.csdn.net/CXLLLK/article/details/86489994 1.极光推送官 ...
- 003_Git & Gitlab 使用指南
2016-02-23 | 9,129字 | 分类于 工具 | 3条评论 去年小组在从 SVN 和 TFS 迁移到 Git 的过程中整理了这份文档,面向的用户是对 Git 和 SV ...
- 5、原生jdbc链接数据库实例-自动取款机
ATM自动取款机需求 一.登陆 1.界面要求:服务选择 1.老用户登陆:进入后输入卡号密码登陆 2.新用户开户:开户需要输入身份证号,记录姓名,开户时间.然后机器给出卡号,原始密码:111111. 卡 ...
- 转载 (三)surging 微服务框架使用系列之我的第一个服务(审计日志)
(三)surging 微服务框架使用系列之我的第一个服务(审计日志) 前言:前面准备了那么久的准备工作,现在终于可以开始构建我们自己的服务了.这篇博客就让我们一起构建自己的第一个服务---审计日志 ...
- OpenCV3计算机视觉Python语言实现笔记(三)
一.使用OpenCV处理图像 1.不同颜色空间的转换 OpenCV中有数百种关于在不同色彩空间之间转换的方法.当前,在计算机视觉中有三种常用的色彩空间:灰度.BGR以及HSV(Hue, Saturat ...
- 剑指offer——矩形覆盖
我们可以用2*1的小矩形横着或者竖着去覆盖更大的矩形.请问用n个2*1的小矩形无重叠地覆盖一个2*n的大矩形,总共有多少种方法? 分析:斐波那契数列的变形 n=0,返回0 n=1,返回1 n=2,返回 ...
- vue是一个渐进式的框架,如何理解“渐进式”
每个框架都不可避免会有自己的一些特点,从而会对使用者有一定的要求,这些要求就是主张,主张有强有弱,它的强势程度会影响在业务开发中的使用方式.使用vue,你可以在原有大系统的上面,把一两个组件改用它实现 ...
- glance系列一:glance基础
一 什么是glance glance即image service,是为虚拟机的创建提供镜像的服务 二 为何要有glance 我们基于openstack是构建基本的Iaas平台对外提供虚拟机,而虚拟机在 ...