javascript - 从 babel-preset-env 中删除 Global "use strict'

标签 javascript node.js babeljs gulp-babel

我想删除 babel-preset-env 在 babel 6.x 中添加的全局 'use strict'。

我阅读了关于 es2015 的另一篇文章。

我尝试了以下 .babelrc 配置,但无济于事:

{
  "presets": [["env", {"loose":true}]],
  "plugins": [
    ["transform-es2015-modules-commonjs", {
      "strict" : false
    }]
  ]
}

我不想像其他帖子为 es2015 建议的那样编辑 node_modules 中的实际文件。这是一个相当的技巧,不会持续存在。

目前唯一的解决方案是使用 gulp-iife 来包装每个文件。真的没有办法在我的 .babelrc 文件中传递一个选项来禁用它吗?

“env”中的哪个插件甚至可以这样做?

谢谢

最佳答案

env预设的modules选项设置为false:

{ 
  "presets": [
       ["env", { "modules": false }]
  ]
}

来自 babel documentation :

modules
"amd" | "umd" | "systemjs" | "commonjs" | false, defaults to "commonjs".

Enable transformation of ES6 module syntax to another module type.

Setting this to false will not transform modules.

关于javascript - 从 babel-preset-env 中删除 Global "use strict',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46271369/

相关文章:

Firebase webpack+babel 函数未部署

javascript - Google SignIn SDK 因抛出错误而失败,发生不可恢复的登录失败 - 捕获错误 : React Native

javascript - 如何将 firestore 集合转换为有用的对象

javascript - 如何在html中嵌入JSON?

node.js - 将 "quick replies"附加到受支持 channel 上的每条消息 - NodeJS 机器人

node.js - 我如何使用express-generator设置babel来使用es6

javascript - 将顶部/左侧偏移坐标转换为日期/时间

javascript - 使用 onclick 调用函数或使用 .click 绑定(bind)事件哪个更好?

javascript - 当键是整数时在javascript es6中解构对象

reactjs - 在 create-react-app 中安装 babel-plugin-styled-components