ani*_*i h 48 javascript use-strict jshint babeljs
我正在使用"使用严格"的函数形式,并且不希望Babel在翻译后添加的全局形式.问题是我使用的是一些没有使用"use strict"模式的库,并且在脚本连接后可能会抛出错误
rco*_*ode 43
正如Babel 6已经提到的那样,它是transform-es2015-modules-commonjs预设,它增加了严格的模式.如果您想在es2015没有模块转换的情况下使用整个预设,请将其放在您的.babelrc文件中:
{
"presets": [
["es2015", { "modules": false }]
]
}
Run Code Online (Sandbox Code Playgroud)
这将禁用模块和严格模式,同时保持启用所有其他es2015转换.
T.J*_*der 25
你是黑名单"useStrict".例如,这是Gruntfile中的一个示例:
babel: {
options: {
blacklist: ["useStrict"],
// ...
},
// ...
}
Run Code Online (Sandbox Code Playgroud)
由于Babel 6现在完全可以选择使用插件,而不是黑名单useStrict,因此您不需要包含该strict-mode插件.如果你正在使用包含它的预设,我认为你必须创建自己的,包括所有其他的,但不是那个.
Ala*_*rce 12
现在有一个babel插件,您可以添加到您的配置,将删除严格模式:babel-plugin-transform-remove-strict-mode."use strict"添加然后删除它有点难看,但它使配置更好.
文档位于GitHub回购中:https: //github.com/genify/babel-plugin-transform-remove-strict-mode
你的.babelrc最终看起来像这样:
{
"presets": ["env"],
"plugins": ["transform-remove-strict-mode"]
}
Run Code Online (Sandbox Code Playgroud)
我也遇到了这个相当荒谬的限制,你不能禁用或覆盖现有预设的设置,而是使用这个预设代替:https://www.npmjs.com/package/babel-preset-es2015-without-strict
plugins: [
[
require("@babel/plugin-transform-modules-commonjs"),
{
strictMode: false
}
],
]
Run Code Online (Sandbox Code Playgroud)
Babel 6 + es2015
我们可以禁用babel-plugin-transform-es2015-modules-commonjs要求babel-plugin-transform-strict-mode.
所以node_modules/babel-plugin-transform-es2015-modules-commonjs/lib/index.js在151行注释以下代码
//inherits: require("babel-plugin-transform-strict-mode"),
Run Code Online (Sandbox Code Playgroud)
你可以告诉 babel 你的代码是一个脚本:
sourceType: "script"
Run Code Online (Sandbox Code Playgroud)
这不会添加use strict. 查看sourceType 选项文档
来源:https : //github.com/babel/babel/issues/7910#issuecomment-388517631
| 归档时间: |
|
| 查看次数: |
38397 次 |
| 最近记录: |