javascript - 如何强制禁用 Babeljs 生成的“使用严格”模式
问题描述
我正在尝试设置将 ES6 和更高版本的 Javascript 语法转换为 ES5 的 Babel 编译器。但是,我遇到了一个奇怪的问题,当它转换为 ES5 时,在行首添加了“use strict”,因为整个项目不是以严格模式编写的,因此会导致错误。我想禁用此功能。我在网上看到了几个解决方案,但没有一个对我有用。我按照这些步骤链接但没有工作。
这就是我的package.json
样子:
{
"name": "webplatform",
"version": "1.0.0",
"description": "Web interface Platform",
"scripts": {
"build": "babel htdocs/es6 -d htdocs/js"
},
"author": "harry",
"license": "ISC",
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/plugin-transform-strict-mode": "^7.2.0",
"@babel/preset-env": "^7.4.3"
}
}
.babelrc
在这里
{
"presets": ["@babel/preset-env"],
"plugins": [
["@babel/plugin-transform-strict-mode", {
"strict": false
}]
]
}
当我运行命令npm run build
时,它会转换一切都很好,只是“使用严格”把我弄乱了:(
解决方案
推荐阅读
- c# - 如何使用firesharp c#库(未知的确切子路径)从firebase检索数据?
- java - Google 驱动器 API 出现 500 内部服务器错误
- python - 处理日期时间
- javafx - 根据单击的按钮将选项卡添加到 TabPane
- c# - 需要在 Xamarin 中的条目中输入值
- angular - Angular 8 本机选择在更改事件上返回 [object object]
- c# - 如何使用采用相同接口的两个实现的类构造函数来解决依赖注入
- javascript - x 秒后终止 childprocess.exec
- firemonkey - C++ Builder 10.4,FMX:表单 TabOrder 问题
- elasticsearch - Elasticsearch 仅重新索引丢失的文档