I\'m using function form of \"use strict\" and don\'t want global form which Babel adds after transpilation. The problem is I\'m using some libraries that aren\'t using \"us
I also came accross this rather ridiculous limitation that you cannot disable or overwrite settings from an existing preset, and have resorted to using this preset instead: https://www.npmjs.com/package/babel-preset-es2015-without-strict
You can tell babel that your code is a script with:
sourceType: "script"
This will not add use strict
. See sourceType option docs
Source: https://github.com/babel/babel/issues/7910#issuecomment-388517631
As it has already been mentioned for Babel 6, it's the transform-es2015-modules-commonjs
preset which adds strict mode.
In case you want to use the whole es2015
preset without module transformations, put this in your .babelrc
file:
{
"presets": [
["es2015", { "modules": false }]
]
}
This will disable modules and strict mode, while keeping all other es2015 transformations enabled.
Since babel 6 you can install firstly babel-cli (if you want to use Babel from the CLI ) or babel-core (to use the Node API). This package does not include modules.
npm install --global babel-cli
# or
npm install --save-dev babel-core
Then install modules that you need. So do not install module for 'strict mode' in your case.
npm install --save-dev babel-plugin-transform-es2015-arrow-functions
And add installed modules in .babelrc file like this:
{
"plugins": ["transform-es2015-arrow-functions"]
}
See details here: https://babeljs.io/blog/2015/10/31/setting-up-babel-6
if you are using https://babeljs.io/repl (v7.8.6
as of this writing), you can remove "use strict";
by selecting Source Type -> Module.
This is not grammatically correct, but will basically work for both Babel 5 and 6 without having to install a module that removes another module.
code.replace(/^"use strict";$/, '')