javascript - 使用 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"]
}
解决方案
推荐阅读
- java - Java 线程转储:并非所有活动线程都被打印
- firebase - Firebase Firestore Emulator Ionic 无法连接
- macos - 安装了iterm2,现在vscode和mac内部终端都打不开了
- cocoa - 在 Excel 中转换 Apple Cocoa Core Data 时间戳
- javascript - 在 HTML 文件中访问从 servlet 发送的 JSON
- python - 如何正确退出在条件函数中应用的函数?
- c# - 如何搜索文本文档中是否存在文件名?
- react-native - 在本机反应中动态创建多个日期选择器
- java - 如何使用 dto 正确创建休息方法
- node.js - 无法执行 git commit