Remove 'use strict' if the file is 'not strict'
Most of the bundlers and transpilers such as babel add 'use strict'
to the above of your file. This plugin will remove them if you add 'not strict'
to that file. You can also use this plugin to remove 'use strict'
from all the files
npm install --save-dev babel-plugin-transform-not-strict
You should also install the peer dependencies:
npm install -save-dev "@babel/core"
- put the following in above the a file that is not strict:
"not strict";
- Add
"babel-plugin-transform-not-strict"
to the list of your babel plugins.
For example, create a babel.config.js
file at the root of the project with the following content:
let presets = [];
let plugins = ["babel-plugin-transform-not-strict"];
module.exports = {
presets: presets,
plugins: plugins,
exclude: "node_modules/**",
sourceMap: "inline",
};
You can also use this plugin to remove 'use strict'
from all the files. Just pass removeAll: true
.
let presets = [];
let plugins = [
[
"babel-plugin-transform-not-strict",
{
removeAll: true,
},
],
];
module.exports = {
presets: presets,
plugins: plugins,
exclude: "node_modules/**",
sourceMap: "inline",
};
You can add more directive or comment triggers for removal of 'use strict'
. In the following example, 'use babel'
directive or comments that include '@babel'
or '@flow'
also instruct the plugin to become active and remove 'use strict'
let presets = [];
let plugins = [
[
"babel-plugin-transform-not-strict",
{
directiveTriggers: ["use babel"],
commentTriggers: ["@babel", "@flow", "* @babel", "* @flow"],
},
],
];
module.exports = {
presets: presets,
plugins: plugins,
exclude: "node_modules/**",
sourceMap: "inline",
};