首页 > 解决方案 > 使用 Grunt-Babel 使 ES6 Internet Explorer 11 兼容

问题描述

我安装了 grunt-babel 以允许我们网站上的 IE 11 用户。现在,对于这些用户,该网站已损坏。除了出现以下我不知道如何解决的错误外,我基本上都取得了成功。

ReferenceError: regeneratorRuntime is not defined

看起来 polyfill 已被弃用,所以我想知道什么是最好的解决方案。

编辑 按照 justDan 和 David 的建议,我安装了 regenerator/runtime 包,现在出现错误require is not defined

此代码将通过浏览器运行。我的公司正在使用自定义 CMS,它需要我们压缩主题文件,并且有很大的部分需要动态填充的文本,这是使用 ES6 模板文字的部分原因。

包.json 文件

{
  "name": "Some Site",
  "version": "1.0.0",
  "description": "",
  "main": "Gruntfile.js",
  "dependencies": {
    "regenerator-runtime": "^0.13.3"
  },
  "devDependencies": {
    "@babel/core": "^7.7.2",
    "@babel/preset-env": "^7.7.1",
    "@babel/preset-es2015": "^7.0.0-beta.53",
    "babel-preset-es2015-nostrict": "^6.6.2",
    "grunt": "^1.0.4",
    "grunt-autoprefixer": "^3.0.4",
    "grunt-babel": "^8.0.0",
    "grunt-contrib-compress": "^1.5.0",
    "grunt-contrib-concat": "^1.0.1",
    "grunt-contrib-cssmin": "^3.0.0",
    "grunt-contrib-imagemin": "^3.1.0",
    "grunt-contrib-less": "^2.0.0",
    "grunt-contrib-uglify": "^4.0.1",
    "grunt-contrib-watch": "^1.1.0",
    "grunt-purifycss": "^0.1.2"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}

.babelrc 文件

{
  "presets": ["@babel/preset-env"]
}

标签: javascriptecmascript-6internet-explorer-11grunt-babel

解决方案


你需要安装并运行这个包

https://www.npmjs.com/package/regenerator-runtime


推荐阅读