12
votes

I want to remove the global 'use strict' that babel-preset-env adds with babel 6.x.

I read the other post about es2015.

I've tried the following .babelrc configuration, to no avail:

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

I do not want to edit the actual file in node_modules as the other post suggested for es2015. That's quite a hack and won't persist.

The only solution so far is to use gulp-iife to wrap every file. Is there really no way to pass an option in my .babelrc file to disable this?

Which plugin in 'env' is even doing this?

Thanks

1
Why would you want to remove it? Strict mode is required for ES modules per spec, and even if you weren’t using ESM, strict mode is great. - Ry-
Because a global strict mode applies to everything in that file, including vendor files that might be a part of the concatenated, minified, final output. I plan to put strict mode manually in my iife's, in my code specifically. If I want to use a third party library, that doesn't support strict mode, a global strict mode will break it. Scoped strict modes inside just my own iife's allow my code to conform to strict, and third party libraries to not. - Captainlonate
Example - {options: {presets: [["babel-preset-es2015", { "modules": false }]]} - Vas

1 Answers

2
votes

Set the modules option of the env preset to false:

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

From 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.