babel

环境搭建基本配置

package.json

{
  "name": "09-babel-demo",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.7.5",
    "@babel/core": "^7.7.5",
    "@babel/plugin-transform-runtime": "^7.7.5",
    "@babel/preset-env": "^7.7.5"
  },
  "dependencies": {
    "@babel/polyfill": "^7.7.0",
    "@babel/runtime": "^7.7.5"
  }
}

.babelrc

{
    "presets": [
        [
            "@babel/preset-env",
            {
                "useBuiltIns": "usage",
                "corejs": 3
            }
        ]
    ],
    "plugins": [
        [
            "@babel/plugin-transform-runtime",
            {
                "absoluteRuntime": false,
                "corejs": 3,
                "helpers": true,
                "regenerator": true,
                "useESModules": false
            }
        ]
    ]
}

babal-polyfill

babal-polyfill => core-js + regenerator
babal7.4之后弃用babel-polyfill,直接使用core-js + regenerator
js新语法打补丁,使低版本浏览器支持新语法

babel-runtime

不污染全集环境,名字前加"_" _promise

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • babel官网 babel 介绍 Babel 是一个通用的多用途 JavaScript 编译器。通过 Babel ...
    锋享前端阅读 5,794评论 0 10
  • 参考了很多文章,只是为了搞清楚babel 7 之后容易搞混的概念。 介绍 本文主要解决如下几个问题: babel ...
    回调的幸福时光阅读 4,461评论 0 0
  • 了解 Babel 各个模块 本文所研究的是 babel 6 版本。babel 6 是 2015年10月30号 发布...
    shianqi阅读 10,076评论 0 7
  • 前言 半年前也写过一篇babel的简单使用文章,当时看了下babel的文档,但是很多地方还不理解,所以文章里没有怎...
    mercurygear阅读 46,175评论 9 100
  • 由于新版本的ECMASscript的强大特性,使我们写js代码更加得心应手,例如:calss,let,for......
    缘自世界阅读 7,486评论 0 2