javascript - 如何阻止 babel 将“this”(用作 IIFE 参数)转换为“void 0”?
问题描述
我想将 ES6 转换为 ES5,因为我们被迫支持 IE11 并且在使用现代脚本时遇到了一些麻烦。我的捆绑包包含 Sweetalert2 并window
获得了undefined
babel。
输入
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
typeof define === 'function' && define.amd ? define(factory) :
(global.Sweetalert2 = factory());
}(this, (function () { 'use strict';
// ...
babel 处理后:
(function (global, factory) {
(typeof exports === "undefined" ? "undefined" : _typeof2(exports)) === 'object' && typeof module !== 'undefined' ? module.exports = factory() : typeof define === 'function' && define.amd ? define(factory) : global.Sweetalert2 = factory();
})(void 0, function () {
'use strict';
// ....
我发现How to stop babel from transpiling 'this' to 'undefined'并且由于 preset-es2015 包被认为已弃用,我认为@babel/preset-env
对我的 babel7 使用 up2date repalcement 是"esmodules": false
但它不起作用。
.babelrc
{
"ignore": ["gulpfile.js"],
"presets": [
[
"@babel/preset-env",
{
"targets": {
"esmodules": false
}
}
]
]
}
解决方案
推荐阅读
- database - 从文件中读取创建矩阵
- api-design - 系统设计面试 - Car API
- c# - 表单打开时如何保留最后使用的文件夹并将其放入文本框中?
- vbscript - 如何在 vbscript 中的数字变量中的 3 位数字后面加上逗号?
- c - 如何从独立于操作系统的 LoadRunner 生成通用唯一标识符、UUID
- python - 无法在 VS Code 中导入 tensorflow.keras
- google-cloud-platform - 尽管服务帐户具有所有者角色,但 GCP 中的存储桶查询权限被拒绝
- github-pages - 如何在 Github Pages 上修改已部署的 create-react-app?
- if-statement - 对可能不是数字的多个单元格求和
- javascript - SOA 自动化使用 javaScript 使用黄瓜特征文件从 json 中获取值