Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove Global "use strict' from babel-preset-env

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

like image 341
Captainlonate Avatar asked Sep 18 '17 03:09

Captainlonate


People also ask

How do I get rid of use strict?

No, you can't disable strict mode per function. Notice how we can define function outside of strict code and then pass it into the function that's strict. You can do something similar in your example — have an object with "sloppy" functions, then pass that object to that strict immediately invoked function.

What is preset ENV in Babel?

@babel/preset-env is a smart preset that allows you to use the latest JavaScript without needing to micromanage which syntax transforms (and optionally, browser polyfills) are needed by your target environment(s). This both makes your life easier and JavaScript bundles smaller!

How do you use Babel presets?

Using a Preset Within a Babel config, if the preset is on npm, you can pass in the name of the preset and Babel will check that it's installed in node_modules already. This is added to the presets config option, which takes an array. Otherwise, you can also specify a relative or absolute path to your presets.

What is Babel choose the correct option?

Babel is a toolchain that is mainly used to convert ECMAScript 2015+ code into a backwards compatible version of JavaScript in current and older browsers or environments.


1 Answers

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.

like image 83
Iwazaru Avatar answered Oct 06 '22 01:10

Iwazaru